using Diligent.WebAPI.Business.Extensions; using Diligent.WebAPI.Contracts.DTOs.SelectionLevel; namespace Diligent.WebAPI.Business.Services { public class SelectionLevelService : ISelectionLevelService { private readonly DatabaseContext _context; private readonly IMapper _mapper; public SelectionLevelService(DatabaseContext context, IMapper mapper) { _context = context; _mapper = mapper; } public async Task> GetAllAsync() => _mapper.Map>(await _context.SelectionLevels.Include(sl => sl.SelectionProcesses).ThenInclude(sp => sp.Applicant).ToListAsync()); public async Task GetByIdAsync(int id) { var sl = await _context.SelectionLevels.FindAsync(id); if (sl is null) throw new EntityNotFoundException("Selection level not found"); return _mapper.Map(sl); } public List GetFilteredLevelsAsync(SelectionProcessFilterDto filters) { var filteredLevels = _context.SelectionLevels.Include(x => x.SelectionProcesses).ThenInclude(sp => sp.Applicant).ToList().FilterLevels(filters); return _mapper.Map>(filteredLevels); } } }