Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SelectionLevelService.cs 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. namespace Diligent.WebAPI.Business.Services
  2. {
  3. public class SelectionLevelService : ISelectionLevelService
  4. {
  5. private readonly DatabaseContext _context;
  6. private readonly IMapper _mapper;
  7. private readonly ILogger<SelectionLevelService> _logger;
  8. public SelectionLevelService(DatabaseContext context, IMapper mapper, ILogger<SelectionLevelService> logger)
  9. {
  10. _context = context;
  11. _mapper = mapper;
  12. _logger = logger;
  13. }
  14. public async Task<List<SelectionLevelResponseWithDataDto>> GetAllAsync()
  15. {
  16. _logger.LogInformation("Start getting all selection levels");
  17. _logger.LogInformation("Getting data from DB");
  18. var fromDb = await _context.SelectionLevels
  19. .Include(sl => sl.SelectionProcesses)
  20. .ThenInclude(sp => sp.Applicant)
  21. .ToListAsync();
  22. _logger.LogInformation($"Received {fromDb.Count} levels from db.");
  23. _logger.LogInformation($"Mapping received ads to SelectionLevelResponseWithDataDto");
  24. var result = _mapper.Map<List<SelectionLevelResponseWithDataDto>>(fromDb);
  25. _logger.LogInformation($"Levels has been mapped and received to client: {result.Count} mapped levels");
  26. return result;
  27. }
  28. public async Task<SelectionLevelResposneDto> GetByIdAsync(int id)
  29. {
  30. _logger.LogInformation($"Start searching Level with id = {id}");
  31. var sl = await _context.SelectionLevels.FindAsync(id);
  32. if (sl is null)
  33. {
  34. _logger.LogError($"Level with id = {id} not found");
  35. throw new EntityNotFoundException("Selection level not found");
  36. }
  37. _logger.LogInformation($"Mapping Level with id = {id} to SelectionLevelResposneDto");
  38. var result = _mapper.Map<SelectionLevelResposneDto>(sl);
  39. _logger.LogInformation($"Level with id = {id} mapped successfully");
  40. return result;
  41. }
  42. public async Task<SelectionLevel> GetByIdEntity(int id)
  43. {
  44. var sl = await _context.SelectionLevels.FindAsync(id);
  45. if (sl is null)
  46. throw new EntityNotFoundException("Selection level not found");
  47. return sl;
  48. }
  49. public List<SelectionLevelResponseWithDataDto> GetFilteredLevelsAsync(SelectionProcessFilterDto filters)
  50. {
  51. _logger.LogInformation("Start getting filtered selection levels");
  52. _logger.LogInformation("Getting data from DB and filter it");
  53. var filteredLevels = _context.SelectionLevels
  54. .Include(x => x.SelectionProcesses)
  55. .ThenInclude(sp => sp.Applicant).ToList()
  56. .FilterLevels(filters);
  57. _logger.LogInformation($"Received {filteredLevels.Count} levels from db.");
  58. _logger.LogInformation($"Mapping received ads to SelectionLevelResponseWithDataDto");
  59. var result = _mapper.Map<List<SelectionLevelResponseWithDataDto>>(filteredLevels);
  60. _logger.LogInformation($"Levels has been mapped and received to client: {result.Count} mapped levels");
  61. return result;
  62. }
  63. }
  64. }