public async Task <IActionResult> UpdateUser(int id, UserForUpdateAdminDto userForUpdateAdminDto) { var userFromRepo = await _repo.GetUser(id); _mapper.Map(userForUpdateAdminDto, userFromRepo); if (await _repo.SaveAll()) { var userToReturn = _mapper.Map <UserForDisplayDetailDto>(userFromRepo); return(CreatedAtRoute("GetUser", new { Controller = "Users", id = userFromRepo.Id }, userToReturn)); } return(BadRequest($"Changes not made for {id} ")); }
public async Task <IActionResult> UpdateUser(int id, UserForUpdateAdminDto userForUpdateAdminDto) { var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); if (id != currentUserId) { return(Unauthorized()); } var userFromRepo = await _repo.GetUser(id); _mapper.Map(userForUpdateAdminDto, userFromRepo); if (await _repo.SaveAll()) { var userToReturn = _mapper.Map <UserForDisplayDetailDto>(userFromRepo); return(CreatedAtRoute("GetUser", new { Controller = "Users", id = userFromRepo.Id }, userToReturn)); } return(BadRequest($"Changes not made for {id} ")); }
public async Task <IActionResult> PasswordChange(int id, PasswordChangeDto passwordChangeDto) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized("Not authorized")); } var userFromRepo = await _repo.GetUser(id); userFromRepo.PasswordHash = _userManager.PasswordHasher .HashPassword(userFromRepo, passwordChangeDto.Password); var result = await _userManager.UpdateAsync(userFromRepo); if (!result.Succeeded) { return(BadRequest("Could Not Change Password")); } await _repo.SaveAll(); return(Ok(new{ message = "Updated Successfully" })); //imp }