public async Task <ApplicantGet> Add(ApplicantAdd applicantAdd) { ApplicantAddValidator applicantAddValidator = new ApplicantAddValidator(_restCountryClient); ValidationResult results = await applicantAddValidator.ValidateAsync(applicantAdd); if (!results.IsValid) { foreach (var failure in results.Errors) { throw new Exception("Property " + failure.PropertyName + " failed validation. Error was: " + failure.ErrorMessage); } } try { Applicant applicant = await _applicantRepository.Add(_mapper.Map <Applicant>(applicantAdd)); return(_mapper.Map <ApplicantGet>(applicant)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <IActionResult> Post([FromBody] ApplicantAdd model) { try { _logger.LogDebug($"REST request to create new {CONTROLLERENTITY} : {JsonConvert.SerializeObject(model)}"); ApplicantGet applicantGet = await _applicantBusiness.Add(model); string getUrl = $"{Request.Host.ToString()}/{applicantGet.Id}"; return(StatusCode(201, new ResponseModel(applicantGet.Id, getUrl))); } catch (Exception exception) { _logger.LogError($"Error Occured in {Request.Path}: {exception.Message}"); return(StatusCode(500, exception.Message)); } }