您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SelectionLevelService.cs 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. .Include(sl => sl.SelectionProcesses)
  22. .ThenInclude(sp => sp.Scheduler)
  23. .ToListAsync();
  24. _logger.LogInformation($"Received {fromDb.Count} levels from db.");
  25. _logger.LogInformation($"Mapping received ads to SelectionLevelResponseWithDataDto");
  26. var result = _mapper.Map<List<SelectionLevelResponseWithDataDto>>(fromDb);
  27. _logger.LogInformation($"Levels has been mapped and received to client: {result.Count} mapped levels");
  28. return result;
  29. }
  30. public async Task<SelectionLevelResposneDto> GetByIdAsync(int id)
  31. {
  32. _logger.LogInformation($"Start searching Level with id = {id}");
  33. var sl = await _context.SelectionLevels.FindAsync(id);
  34. if (sl is null)
  35. {
  36. _logger.LogError($"Level with id = {id} not found");
  37. throw new EntityNotFoundException("Selection level not found");
  38. }
  39. _logger.LogInformation($"Mapping Level with id = {id} to SelectionLevelResposneDto");
  40. var result = _mapper.Map<SelectionLevelResposneDto>(sl);
  41. _logger.LogInformation($"Level with id = {id} mapped successfully");
  42. return result;
  43. }
  44. public async Task<SelectionLevel> GetByIdEntity(int id)
  45. {
  46. _logger.LogInformation($"Start searching Level with id = {id}");
  47. var sl = await _context.SelectionLevels.FindAsync(id);
  48. if (sl is null)
  49. {
  50. _logger.LogError($"Level with id = {id} not found");
  51. throw new EntityNotFoundException("Selection level not found");
  52. }
  53. _logger.LogInformation($"Level with id = {id} found and returned to client");
  54. return sl;
  55. }
  56. public List<SelectionLevelResponseWithDataDto> GetFilteredLevelsAsync(SelectionProcessFilterDto filters)
  57. {
  58. _logger.LogInformation("Start getting filtered selection levels");
  59. _logger.LogInformation("Getting data from DB and filter it");
  60. var filteredLevels = _context.SelectionLevels
  61. .Include(x => x.SelectionProcesses)
  62. .ThenInclude(sp => sp.Applicant).ToList()
  63. .FilterLevels(filters);
  64. _logger.LogInformation($"Received {filteredLevels.Count} levels from db.");
  65. _logger.LogInformation($"Mapping received ads to SelectionLevelResponseWithDataDto");
  66. var result = _mapper.Map<List<SelectionLevelResponseWithDataDto>>(filteredLevels);
  67. _logger.LogInformation($"Levels has been mapped and received to client: {result.Count} mapped levels");
  68. return result;
  69. }
  70. }
  71. }