public async Task <IActionResult> UpdateAsync(Guid ApplicantId, [FromBody] UpdateApplicantRequest request) { var applicant = await _applicantService.GetApplicantByIdAsync(ApplicantId); if (applicant?.EmailAddress == request.EmailAddress) { return(BadRequest("User with this email already exists")); } //TODO: externlize conversions, using AutoMapper applicant.Name = request.Name; applicant.FamilyName = request.FamilyName; applicant.Address = request.Address; applicant.CountryOfOrigin = request.CountryOfOrigin; applicant.EmailAddress = request.EmailAddress; applicant.Age = request.Age; applicant.Hired = request.Hired; var updated = await _applicantService.UpdateApplicantAsync(applicant); if (updated) { return(Ok(applicant.Id)); } return(NotFound()); }
public async Task UpdateApplicant(UpdateApplicantRequest updateApplicantRequest) { try { var entity = await this._unitOfWork .ApplicantRepository .Find(applicant => applicant.Id == updateApplicantRequest.Id); if (entity == null) { throw new ObjectNotFoundException(); } entity.Address = updateApplicantRequest.Address; entity.Name = updateApplicantRequest.Name; entity.FamilyName = updateApplicantRequest.FamilyName; entity.CountryOfOrigin = updateApplicantRequest.CountryOfOrigin; entity.EmailAddress = updateApplicantRequest.EmailAddress; entity.Age = updateApplicantRequest.Age; entity.Hired = updateApplicantRequest.Hired; this._unitOfWork.ApplicantRepository.Update(entity); await this._unitOfWork.SaveChanges(); } catch (Exception ex) { this._logger.LogError("UpdateApplicant has an error with {id}", ex, updateApplicantRequest.Id); throw; } }
public async Task <IActionResult> UpdateAsync(UpdateApplicantRequest request) { try { await _applicantService.UpdateApplicant(new Domain.Applicant.Models.UpdateApplicantRequest() { Id = request.Id, Name = request.Name, FamilyName = request.FamilyName, Address = request.Address, CountryOfOrigin = request.CountryOfOrigin, EmailAddress = request.EmailAddress, Age = request.Age, Hired = request.Hired, }); return(Ok()); } catch (System.Exception ex) { this._logger.LogError(ex, "error while update"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }