You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CategoryService.cs 867B

123456789101112131415161718192021222324252627
  1. using Diligent.WebAPI.Contracts.DTOs.Categories;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Diligent.WebAPI.Business.Services
  8. {
  9. public class CategoryService : ICategoryService
  10. {
  11. private readonly DatabaseContext _context;
  12. private readonly IMapper _mapper;
  13. public CategoryService(DatabaseContext context, IMapper mapper)
  14. {
  15. _context = context;
  16. _mapper = mapper;
  17. }
  18. public async Task<List<CategoriesNamesResponse>> GetCategoriesNamesAsync() =>
  19. _mapper.Map<List<CategoriesNamesResponse>>(await _context.Categories.ToListAsync());
  20. public async Task<Category> GetCategoryEntityById(int id) =>
  21. await _context.Categories.Where(x => x.Id == id).FirstOrDefaultAsync();
  22. }
  23. }