30 lines
983 B
C#
30 lines
983 B
C#
using AutoMapper;
|
|
using HardwarePerformance.Models.DTOs;
|
|
using HardwarePerformance.Repositories;
|
|
|
|
namespace HardwarePerformance.Services
|
|
{
|
|
public class CategoryService : ICategoryService
|
|
{
|
|
private readonly ICategoryRepository _categoryRepository;
|
|
private readonly IMapper _mapper;
|
|
|
|
public CategoryService(ICategoryRepository categoryRepository, IMapper mapper)
|
|
{
|
|
_categoryRepository = categoryRepository;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public async Task<IEnumerable<CategoryDto>> GetAllCategoriesAsync()
|
|
{
|
|
var categories = await _categoryRepository.GetAllAsync();
|
|
return _mapper.Map<IEnumerable<CategoryDto>>(categories);
|
|
}
|
|
|
|
public async Task<CategoryDto?> GetCategoryByIdAsync(int id)
|
|
{
|
|
var category = await _categoryRepository.GetByIdAsync(id);
|
|
return category != null ? _mapper.Map<CategoryDto>(category) : null;
|
|
}
|
|
}
|
|
} |