public async Task <IActionResult> ChangePassword([FromBody] PasswordUpdateViewModel model) { try { var idDoUsuario = HttpContext.User.Claims.First(a => a.Type == "id").Value; var usr = await repositorio.Get(int.Parse(idDoUsuario)); usr.Senha = model.Senha; await repositorio.Put(usr); return(Ok(usr)); } catch (System.Exception) { throw; } }
public async Task <IActionResult> ChangePassword([FromBody] PasswordUpdateViewModel model) { User user = await UserManager.GetUserAsync(User); if (user == null) { return(Unauthorized()); } IdentityResult result = await UserManager.ChangePasswordAsync(user, model.CurrentPassword, model.NewPassword); if (!result.Succeeded) { return(BadRequest(result.Errors)); } return(Ok()); }