public async Task <IActionResult> UpdateApplicant(string Id, [FromBody] ApplicantResource resource) { try { var result = await _applicantService.UpdateApplicant(Id, resource); if (result.ResponseMessage != "Successfully Updated" && result.ResponseMessage != "Entity To Update Can Not Be Found" && result.Errors != null) { ModelState.AddModelError("", "Something went wrong when updating the record "); return(StatusCode(400, ModelState)); } if (result.Errors != null) { return(BadRequest(result.Errors)); } return(StatusCode(201, result.ResponseMessage)); } catch (Exception ex) { _logger.LogInformation(ex.Message); _logger.LogInformation(ex.InnerException.ToString()); throw ex; } }
public async Task<ApplicantResponseMessage> AddApplicant(ApplicantResource resource) { try { var validation = new SaveApplicantResourceValidator(); var validationResult = validation.Validate(resource); if (!validationResult.IsValid) { return new ApplicantResponseMessage { Errors = validationResult.Errors }; } var applicant = new Applicant(); applicant.Name = resource.Name; applicant.Address = resource.Address; applicant.Age = resource.Age; applicant.CountryOfOrigin = resource.CountryOfOrigin; applicant.EMailAdress = resource.EMailAdress; applicant.FamilyName = resource.FamilyName; applicant.Hired = resource.Hired; await _unitOfWork.Applicant.SaveAsync(applicant); return new ApplicantResponseMessage { ResponseMessage = "Successfully Saved" }; } catch(Exception ex) { _logger.LogInformation(ex.Message); throw ex; } }
public async Task <IActionResult> AddApplicant([FromBody] ApplicantResource ApplicantResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var ApplicantToAdd = _mapper.Map <ApplicantResource, Applicants>(ApplicantResource); _repo.AddApplicant(ApplicantToAdd); await _unitofwork.CompleteAsync(); return(StatusCode(201)); }
public async Task <IActionResult> UpdateApplicant(int id, [FromBody] ApplicantResource ApplicantResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Applicants applicants = await _repo.Get(id); if (applicants == null) { return(NotFound()); } _mapper.Map <ApplicantResource, Applicants>(ApplicantResource, applicants); await _unitofwork.CompleteAsync(); return(StatusCode(202)); }
public async Task<ApplicantResponseMessage> UpdateApplicant(string id, ApplicantResource resource) { try { var validation = new SaveApplicantResourceValidator(); var findId = await GetApplicantById(id); if (findId != null) { var validationResult = validation.Validate(resource); if (!validationResult.IsValid) { return new ApplicantResponseMessage { Errors = validationResult.Errors }; } //var applicant = new Applicant(); findId.Name = resource.Name; findId.Address = resource.Address; findId.Age = resource.Age; findId.CountryOfOrigin = resource.CountryOfOrigin; findId.EMailAdress = resource.EMailAdress; findId.FamilyName = resource.FamilyName; findId.Hired = resource.Hired; await _unitOfWork.Applicant.UpdateAsync(findId); return new ApplicantResponseMessage { ResponseMessage = "Successfully Updated" }; } else { return new ApplicantResponseMessage { ResponseMessage = "Entity To Update Can Not Be Found" }; } } catch (Exception ex) { _logger.LogInformation(ex.Message); throw ex; } }