public async Task<IActionResult> UpdateUser(int id, UserForUpdatesDto userForUpdateDto) { if(id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) return Unauthorized(); var userFromRepo = await _repo.GetUser(id); _mapper.Map(userForUpdateDto, userFromRepo); if (await _repo.SaveAll()) return NoContent(); throw new Exception($"Updating user {id} failed on save"); }
public async Task <IActionResult> UpdateUser(int id, UserForUpdatesDto userForUpdate) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var userFromRepo = await this._datingRepository.GetUser(id); _mapper.Map(userForUpdate, userFromRepo); if (await _datingRepository.SaveAll()) { return(NoContent()); } throw new Exception($"Update user with id {id} failed on saving"); }
public async Task <IActionResult> UpdateUser(int id, UserForUpdatesDto userForUpdateDto) { // da li isti user koji je ulogovan hoce da pristupi ovoj ruti // ulogovani korisnik moze da mijenja samo svoj profil if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var userFromRepo = await _repo.GetUser(id); _mapper.Map(userForUpdateDto, 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) { Console.WriteLine("ClaimType.NameIndentifier: " + User.FindFirst(ClaimTypes.NameIdentifier).Value); Console.WriteLine("update user id: " + id); if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var userFromRepo = await _repo.GetUser(id); _mapper.Map(userForUpdatesDto, userFromRepo); // update success status if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception($"Updating user {id} failed on save"); }