public async Task <IHttpActionResult> Update([FromBody] UpdatePersonnelProfileDto personnel) { if (personnel == null) { return(BadRequest()); } if (!ModelState.IsValid) { string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState); return(BadRequest(errorMessage)); } try { var username = User.Identity.Name; var result = await _personnelProfileService.Update(personnel, username); if (!result.IsValid) { return(BadRequest(result.Message)); } } catch (LogicalException ex) { return(BadRequest(ex.Message)); } catch { return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE)); } return(Ok()); }
public async Task <CustomResult> Update(UpdatePersonnelProfileDto dto, string username) { var connectedUser = await _authRepository.FindUserByUsernameAsync(username); if (connectedUser == null) { try { throw new LogicalException(); } catch (LogicalException ex) { _logger.LogLogicalError(ex, "personnel with code: {0}, " + "corresponding user is not available!", username); throw; } } var personnel = _personnelRepository.Get(q => q.Code == username).SingleOrDefault(); if (personnel != null) { personnel.Name = dto.Name; personnel.LastName = dto.LastName; personnel.Mobile = dto.Mobile; personnel.IsPresent = dto.IsPresent; _personnelRepository.Update(personnel); if (!string.IsNullOrEmpty(dto.Password) && !string.IsNullOrEmpty(dto.ConfirmPassword)) { var result = await _authRepository.UpdateUserAsync(connectedUser, dto.Password); if (!result.Succeeded) { return(new CustomResult { Message = "updating password was not successful" }); } } } else { try { throw new LogicalException(); } catch (LogicalException ex) { _logger.LogLogicalError (ex, "Personnel entity with the id: '{0}', is not available." + " update operation failed.", personnel.Id); throw; } } return(new CustomResult { IsValid = true }); }