public async Task <IActionResult> UpdateUser(string username, UserForUpdateViewModel userForUpdate) { if (username != User.FindFirst(ClaimTypes.Email).Value) { throw new UnauthorizedAccessException(); } bool isUpdated = await _userService.UpdateUser(username, userForUpdate); return(Ok(isUpdated)); }
public async Task <bool> UpdateUser(string username, UserForUpdateViewModel userForUpdate) { var user = await _datingRepository.GetUser(username); if (user == null) { throw new Exception($"user with id {username} is not found"); } _mapper.Map(userForUpdate, user); return(await _datingRepository.SaveAll()); }
public async Task Update(Guid id, UserForUpdateViewModel userViewModel) { var user = await _userRepository.GetByIdAsync(id); if (user != null) { user.Img = userViewModel.Img; user.Role = userViewModel.Role; await _userRepository.UpdateAsync(user); } }
public async Task <IActionResult> UpdateUser(Guid id, [FromBody] UserForUpdateViewModel userViewModel) { var user = _userViewModelService.GetById(id); if (user == null) { return(NotFound()); } await _userViewModelService.Update(id, userViewModel); return(NoContent()); }
public async Task <IActionResult> UpdateUser(int id, [FromBody] UserForUpdateViewModel user) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var userFromrepo = await repo.GetUserByID(id); mapper.Map(user, userFromrepo); if (await repo.SaveAll()) { return(NoContent()); } throw new Exception($"Updating user {id} failed on save"); }