public async Task <IActionResult> ChangePassword(PasswordViewModel model) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { var userId = User.GetUserId(); var isValid = await _userService.ChangePassword(userId.ToString(), model.CurrentPassword, model.Password); if (isValid) { await _signInManager.SignOutAsync(); return(new OkObjectResult(new GenericResult(true))); } else { return(new OkObjectResult(new GenericResult(false))); } } }
public async Task <ActionResult <AppUser_AppUserDTO> > ChangePassword([FromBody] AppUser_ProfileChangePasswordDTO AppUser_ProfileChangePasswordDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } this.CurrentContext.UserId = ExtractUserId(); AppUser AppUser = new AppUser { Id = CurrentContext.UserId, Password = AppUser_ProfileChangePasswordDTO.OldPassword, NewPassword = AppUser_ProfileChangePasswordDTO.NewPassword, }; AppUser.BaseLanguage = CurrentContext.Language; AppUser = await AppUserService.ChangePassword(AppUser); AppUser_AppUserDTO AppUser_AppUserDTO = new AppUser_AppUserDTO(AppUser); if (AppUser.IsValidated) { return(AppUser_AppUserDTO); } else { return(BadRequest(AppUser_AppUserDTO)); } }