Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SelectionLevelService.cs 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. _logger.LogInformation($"Start searching Level with id = {id}");
  45. var sl = await _context.SelectionLevels.FindAsync(id);
  46. if (sl is null)
  47. {
  48. _logger.LogError($"Level with id = {id} not found");
  49. throw new EntityNotFoundException("Selection level not found");
  50. }
  51. _logger.LogInformation($"Level with id = {id} found and returned to client");
  52. return sl;
  53. }
  54. public List<SelectionLevelResponseWithDataDto> GetFilteredLevelsAsync(SelectionProcessFilterDto filters)
  55. {
  56. _logger.LogInformation("Start getting filtered selection levels");
  57. _logger.LogInformation("Getting data from DB and filter it");
  58. var filteredLevels = _context.SelectionLevels
  59. .Include(x => x.SelectionProcesses)
  60. .ThenInclude(sp => sp.Applicant).ToList()
  61. .FilterLevels(filters);
  62. _logger.LogInformation($"Received {filteredLevels.Count} levels from db.");
  63. _logger.LogInformation($"Mapping received ads to SelectionLevelResponseWithDataDto");
  64. var result = _mapper.Map<List<SelectionLevelResponseWithDataDto>>(filteredLevels);
  65. _logger.LogInformation($"Levels has been mapped and received to client: {result.Count} mapped levels");
  66. return result;
  67. }
  68. }
  69. }