public async Task <IActionResult> UpdateUser(int id, UserForUpdatesDTO userForUpdatesDTO) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var userFromRepo = await _repo.GetUser(id); _mapper.Map(userForUpdatesDTO, userFromRepo); if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception($"Updating user {id} failed on save."); }
public async Task <IActionResult> UpdateUser(int id, UserForUpdatesDTO userForUpdatesDTO) { // Checks the id passed in the route to the one in the jwt to make sure they are the same if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var userFromRepo = await _repo.GetUser(id); _mapper.Map(userForUpdatesDTO, userFromRepo); if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception($"Updating user {id} failed on save"); }