public async Task <IActionResult> Post([FromBody] CreateApplicantDto applicantDto) { var result = await _applicant.Create(applicantDto); return(result > -1 ? (IActionResult)CreatedAtAction(nameof(Get), new { id = result }, applicantDto) : BadRequest()); }
public async Task <ActionResult <CreateApplicantDto> > PostApplicant(CreateApplicantDto createApplicantDto) { var applicantId = await _service.CreateApplicant(createApplicantDto); return(CreatedAtAction( nameof(GetApplicant), new { id = applicantId }, new { id = applicantId })); }
public async Task <Response <Applicant> > SaveApplicant(CreateApplicantDto model) { var response = new Response <Applicant>(); var applicant = new Applicant { Name = model.Name, Address = model.Address, Age = model.Age, CountryOfOrigin = model.CountryOfOrigin, EmailAddress = model.EmailAddress, FamilyName = model.FamilyName, Hired = model.Hired }; var validationErrors = await Helper.Helper.ApplicantValidationErrors(applicant); var hasValidationErrors = validationErrors.FirstOrDefault(e => e.HasValidationErrors); if (hasValidationErrors != null) { response.Success = false; response.Errors = validationErrors; return(response); } var applicantExists = await _unitOfWork.applicant.FindByEmail(model.EmailAddress); if (applicantExists == null) { await _unitOfWork.applicant.Save(applicant); var fetchApplicant = await _unitOfWork.applicant.FindByEmail(applicant.EmailAddress); response.Message = "Applicant saved successfully"; response.Success = true; response.Data = fetchApplicant; return(response); } response.Message = $"Applicant with these email {model.EmailAddress} already been added"; response.Success = false; return(response); }
public async Task <IActionResult> Create([FromBody] CreateApplicantDto model) { try { var applicantService = new ApplicantService(_unitOfWork); var response = await applicantService.SaveApplicant(model); if (!response.Success) { _logger.LogInformation($"Bad request on creation of an applicant with email {model.EmailAddress}."); return(BadRequest(response)); } _logger.LogInformation($"Applicant was created successfully with id {response.Data.ID}."); return(Created($"http://localhost:5000/api/user/{response.Data.ID}", response)); } catch (Exception e) { _logger.LogInformation(e.Message); return(StatusCode(500, e.Message)); } }
public async Task <int> Create(CreateApplicantDto applicantDto) { return(await _mediator.Send(_mapper.Map <CreateApplicantCommand>(applicantDto))); }