| CreateMap<Applicant, AdApplicantViewDto>(); | CreateMap<Applicant, AdApplicantViewDto>(); | ||||
| CreateMap<Applicant, ApplicantScheduleViewDto>(); | CreateMap<Applicant, ApplicantScheduleViewDto>(); | ||||
| CreateMap<Applicant, PatternApplicantViewDto>(); | CreateMap<Applicant, PatternApplicantViewDto>(); | ||||
| CreateMap<Applicant, ApplicantOptionsDTO>(); | |||||
| #endregion | #endregion | ||||
| #region DTOs to Models | #region DTOs to Models |
| return result; | return result; | ||||
| } | } | ||||
| public async Task<List<ApplicantOptionsDTO>> GetOptions() | |||||
| { | |||||
| var res = await _context.Applicants.ToListAsync(); | |||||
| return _mapper.Map<List<ApplicantOptionsDTO>>(res); | |||||
| } | |||||
| public async Task<ServiceResponseDTO<object>> InitializeProcess(ApplicantProcessRequestDTO model) | |||||
| { | |||||
| var applicant = await _context.Applicants.Include(n => n.SelectionProcesses).Where(n=> n.ApplicantId ==model.ApplicantId).FirstOrDefaultAsync(); | |||||
| if (applicant == null) | |||||
| return new ServiceResponseDTO<object> | |||||
| { | |||||
| IsError = true, | |||||
| ErrorMessage = "Applicant does not exist." | |||||
| }; | |||||
| applicant.SelectionProcesses.Add(new SelectionProcess | |||||
| { | |||||
| Name = StringGenerator.GenerateRandomPassword(), | |||||
| SchedulerId = model.SchedulerId, | |||||
| SelectionLevelId = 1, | |||||
| Status = model.Appointment != null ? "Zakazan" : "Čeka na zakazivanje", | |||||
| Date = model.Appointment | |||||
| }); | |||||
| await _context.SaveChangesAsync(); | |||||
| return new ServiceResponseDTO<object> | |||||
| { | |||||
| Data = true | |||||
| }; | |||||
| } | |||||
| //public async Task CreateApplicant(ApplicantCreateDto applicantCreateDto) | //public async Task CreateApplicant(ApplicantCreateDto applicantCreateDto) | ||||
| //{ | //{ | ||||
| // var applicant = _mapper.Map<Applicant>(applicantCreateDto); | // var applicant = _mapper.Map<Applicant>(applicantCreateDto); |
| | | ||||
| using Diligent.WebAPI.Contracts.DTOs.Applicant; | |||||
| namespace Diligent.WebAPI.Business.Services.Interfaces | namespace Diligent.WebAPI.Business.Services.Interfaces | ||||
| { | { | ||||
| public interface IApplicantService | public interface IApplicantService | ||||
| Task<ApplicantViewDto> GetById(int id); | Task<ApplicantViewDto> GetById(int id); | ||||
| Task<ApplicantViewDto> GetApplicantWithSelectionProcessesById(int id); | Task<ApplicantViewDto> GetApplicantWithSelectionProcessesById(int id); | ||||
| Task DeleteApplicant(int id); | Task DeleteApplicant(int id); | ||||
| Task<List<ApplicantOptionsDTO>> GetOptions(); | |||||
| Task<ServiceResponseDTO<object>> InitializeProcess(ApplicantProcessRequestDTO model); | |||||
| //Task CreateApplicant(ApplicantCreateDto applicantCreateDto); | //Task CreateApplicant(ApplicantCreateDto applicantCreateDto); | ||||
| //Task UpdateApplicant(int id, ApplicantUpdateDto applicantUpdateDto); | //Task UpdateApplicant(int id, ApplicantUpdateDto applicantUpdateDto); | ||||
| } | } |
| namespace Diligent.WebAPI.Contracts.DTOs.Applicant | |||||
| { | |||||
| public class ApplicantOptionsDTO | |||||
| { | |||||
| public int ApplicantId { get; set; } | |||||
| public string FirstName { get; set; } | |||||
| public string LastName { get; set; } | |||||
| } | |||||
| } |
| namespace Diligent.WebAPI.Contracts.DTOs.Applicant | |||||
| { | |||||
| public class ApplicantProcessRequestDTO | |||||
| { | |||||
| [Required] | |||||
| public int ApplicantId { get; set; } | |||||
| public int SchedulerId { get; set; } | |||||
| public DateTime? Appointment { get; set; } | |||||
| } | |||||
| } |
| return Ok(await _applicantService.GetApplicantWithSelectionProcessesById(id)); | return Ok(await _applicantService.GetApplicantWithSelectionProcessesById(id)); | ||||
| } | } | ||||
| [HttpGet("options")] | |||||
| public async Task<IActionResult> GetOptions() | |||||
| { | |||||
| return Ok(await _applicantService.GetOptions()); | |||||
| } | |||||
| [HttpPost("selection-init")] | |||||
| public async Task<IActionResult> InitSelection(ApplicantProcessRequestDTO model) | |||||
| { | |||||
| await _applicantService.InitializeProcess(model); | |||||
| return Ok(model); | |||||
| } | |||||
| } | } | ||||
| } | } |