| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- namespace Diligent.WebAPI.Business.Services
- {
- public class SelectionProcessService : ISelectionProcessService
- {
- private readonly DatabaseContext _context;
- private readonly IMapper _mapper;
- private readonly ILogger<SelectionProcessService> _logger;
-
- public SelectionProcessService(DatabaseContext context, IMapper mapper, ILogger<SelectionProcessService> logger)
- {
- _context = context;
- _mapper = mapper;
- _logger = logger;
- }
-
- public async Task<List<SelectionProcessResposneDto>> GetAllAsync()
- {
- _logger.LogInformation("Start getting all Selection Processes");
- _logger.LogInformation("Getting data from DB");
- var fromDB = await _context.SelectionProcesses.ToListAsync();
- _logger.LogInformation($"Received {fromDB.Count} processes from db.");
- _logger.LogInformation($"Mapping received ads to SelectionProcessResposneDto");
- var result = _mapper.Map<List<SelectionProcessResposneDto>>(fromDB);
- _logger.LogInformation($"Processes has been mapped and received to client: {result.Count} mapped processes");
- return result;
- }
- public async Task<bool> FinishSelectionProcess(SelectionProcessCreateDto model)
- {
- _logger.LogInformation($"Start finishing selection process with {model.Id}");
- var sp = await _context.SelectionProcesses.FindAsync(model.Id);
-
- if (sp is null)
- {
- _logger.LogError($"Process with id = {model.Id} not found");
- throw new EntityNotFoundException("Selection process not found");
- }
-
- _logger.LogError($"Changing status for {model.Id}");
- sp.Status = "Odrađen";
-
- _logger.LogError($"Skipping throught levels to come to next level");
- var nextLevel = _context.SelectionLevels.AsEnumerable()
- .SkipWhile(obj => obj.Id != sp.SelectionLevelId)
- .Skip(1).First();
-
- if (nextLevel is null)
- {
- _logger.LogError($"Applicant is in the last selection level");
- throw new EntityNotFoundException("Candidate came to the last selection level");
- }
-
- SelectionProcess newProcess = new SelectionProcess
- {
- Name = model.Name,
- SelectionLevelId = nextLevel.Id,
- Status = "Čeka na zakazivanje",
- ApplicantId = sp.ApplicantId,
- SchedulerId = model.SchedulerId
- };
- _context.SelectionProcesses.Add(newProcess);
- _logger.LogError($"Create and add new selection process");
- var result = await _context.SaveChangesAsync() > 0;
- _logger.LogError($"Saved changes to db");
- return result;
- }
- }
- }
|