namespace Diligent.WebAPI.Business.Services { public class SelectionLevelService : ISelectionLevelService { private readonly DatabaseContext _context; private readonly IMapper _mapper; private readonly ILogger _logger; public SelectionLevelService(DatabaseContext context, IMapper mapper, ILogger logger) { _context = context; _mapper = mapper; _logger = logger; } public async Task> GetAllAsync() { _logger.LogInformation("Start getting all selection levels"); _logger.LogInformation("Getting data from DB"); var fromDb = await _context.SelectionLevels .Include(sl => sl.SelectionProcesses) .ThenInclude(sp => sp.Applicant) .ToListAsync(); _logger.LogInformation($"Received {fromDb.Count} levels from db."); _logger.LogInformation($"Mapping received ads to SelectionLevelResponseWithDataDto"); var result = _mapper.Map>(fromDb); _logger.LogInformation($"Levels has been mapped and received to client: {result.Count} mapped levels"); return result; } public async Task GetByIdAsync(int id) { _logger.LogInformation($"Start searching Level with id = {id}"); var sl = await _context.SelectionLevels.FindAsync(id); if (sl is null) { _logger.LogError($"Level with id = {id} not found"); throw new EntityNotFoundException("Selection level not found"); } _logger.LogInformation($"Mapping Level with id = {id} to SelectionLevelResposneDto"); var result = _mapper.Map(sl); _logger.LogInformation($"Level with id = {id} mapped successfully"); return result; } public async Task GetByIdEntity(int id) { _logger.LogInformation($"Start searching Level with id = {id}"); var sl = await _context.SelectionLevels.FindAsync(id); if (sl is null) { _logger.LogError($"Level with id = {id} not found"); throw new EntityNotFoundException("Selection level not found"); } _logger.LogInformation($"Level with id = {id} found and returned to client"); return sl; } public List GetFilteredLevelsAsync(SelectionProcessFilterDto filters) { _logger.LogInformation("Start getting filtered selection levels"); _logger.LogInformation("Getting data from DB and filter it"); var filteredLevels = _context.SelectionLevels .Include(x => x.SelectionProcesses) .ThenInclude(sp => sp.Applicant).ToList() .FilterLevels(filters); _logger.LogInformation($"Received {filteredLevels.Count} levels from db."); _logger.LogInformation($"Mapping received ads to SelectionLevelResponseWithDataDto"); var result = _mapper.Map>(filteredLevels); _logger.LogInformation($"Levels has been mapped and received to client: {result.Count} mapped levels"); return result; } } }