Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SelectionProcessService.cs 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. namespace Diligent.WebAPI.Business.Services
  2. {
  3. public class SelectionProcessService : ISelectionProcessService
  4. {
  5. private readonly DatabaseContext _context;
  6. private readonly IMapper _mapper;
  7. private readonly ILogger<SelectionProcessService> _logger;
  8. public SelectionProcessService(DatabaseContext context, IMapper mapper, ILogger<SelectionProcessService> logger)
  9. {
  10. _context = context;
  11. _mapper = mapper;
  12. _logger = logger;
  13. }
  14. public async Task<List<SelectionProcessResposneDto>> GetAllAsync()
  15. {
  16. _logger.LogInformation("Start getting all Selection Processes");
  17. _logger.LogInformation("Getting data from DB");
  18. var fromDB = await _context.SelectionProcesses.ToListAsync();
  19. _logger.LogInformation($"Received {fromDB.Count} processes from db.");
  20. _logger.LogInformation($"Mapping received ads to SelectionProcessResposneDto");
  21. var result = _mapper.Map<List<SelectionProcessResposneDto>>(fromDB);
  22. _logger.LogInformation($"Processes has been mapped and received to client: {result.Count} mapped processes");
  23. return result;
  24. }
  25. public async Task<bool> FinishSelectionProcess(SelectionProcessCreateDto model)
  26. {
  27. _logger.LogInformation($"Start finishing selection process with {model.Id}");
  28. var sp = await _context.SelectionProcesses.FindAsync(model.Id);
  29. if (sp is null)
  30. {
  31. _logger.LogError($"Process with id = {model.Id} not found");
  32. throw new EntityNotFoundException("Selection process not found");
  33. }
  34. _logger.LogError($"Changing status for {model.Id}");
  35. sp.Status = "Odrađen";
  36. _logger.LogError($"Skipping throught levels to come to next level");
  37. var nextLevel = _context.SelectionLevels.AsEnumerable()
  38. .SkipWhile(obj => obj.Id != sp.SelectionLevelId)
  39. .Skip(1).First();
  40. if (nextLevel is null)
  41. {
  42. _logger.LogError($"Applicant is in the last selection level");
  43. throw new EntityNotFoundException("Candidate came to the last selection level");
  44. }
  45. SelectionProcess newProcess = new SelectionProcess
  46. {
  47. Name = model.Name,
  48. SelectionLevelId = nextLevel.Id,
  49. Status = "Čeka na zakazivanje",
  50. ApplicantId = sp.ApplicantId,
  51. SchedulerId = model.SchedulerId
  52. };
  53. _context.SelectionProcesses.Add(newProcess);
  54. _logger.LogError($"Create and add new selection process");
  55. var result = await _context.SaveChangesAsync() > 0;
  56. _logger.LogError($"Saved changes to db");
  57. return result;
  58. }
  59. }
  60. }