feature/1999_initial_interview_be a BE_dev 3 anni fa
| @@ -11,6 +11,7 @@ namespace Diligent.WebAPI.Business.MappingProfiles | |||
| CreateMap<Applicant, AdApplicantViewDto>(); | |||
| CreateMap<Applicant, ApplicantScheduleViewDto>(); | |||
| CreateMap<Applicant, PatternApplicantViewDto>(); | |||
| CreateMap<Applicant, ApplicantOptionsDTO>(); | |||
| #endregion | |||
| #region DTOs to Models | |||
| @@ -111,6 +111,40 @@ | |||
| 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) | |||
| //{ | |||
| // var applicant = _mapper.Map<Applicant>(applicantCreateDto); | |||
| @@ -1,4 +1,6 @@ | |||
| | |||
| using Diligent.WebAPI.Contracts.DTOs.Applicant; | |||
| namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| { | |||
| public interface IApplicantService | |||
| @@ -8,6 +10,8 @@ namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| Task<ApplicantViewDto> GetById(int id); | |||
| Task<ApplicantViewDto> GetApplicantWithSelectionProcessesById(int id); | |||
| Task DeleteApplicant(int id); | |||
| Task<List<ApplicantOptionsDTO>> GetOptions(); | |||
| Task<ServiceResponseDTO<object>> InitializeProcess(ApplicantProcessRequestDTO model); | |||
| //Task CreateApplicant(ApplicantCreateDto applicantCreateDto); | |||
| //Task UpdateApplicant(int id, ApplicantUpdateDto applicantUpdateDto); | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| namespace Diligent.WebAPI.Contracts.DTOs.Applicant | |||
| { | |||
| public class ApplicantOptionsDTO | |||
| { | |||
| public int ApplicantId { get; set; } | |||
| public string FirstName { get; set; } | |||
| public string LastName { get; set; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| 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; } | |||
| } | |||
| } | |||
| @@ -43,5 +43,18 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| 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(); | |||
| } | |||
| } | |||
| } | |||