public async Task <IActionResult> Edit() { var user = await UserMgr.GetUserAsync(HttpContext.User); if (user == null) { return(NotFound()); } return(View(user)); }
public async Task <IActionResult> Edit(string UserName, string password, string old_password) { var user = await UserMgr.GetUserAsync(HttpContext.User); if (user != null) { if (!string.IsNullOrEmpty(UserName)) { user.UserName = UserName; } else { ModelState.AddModelError("", "Username cannot be empty"); } if (!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(old_password)) { IdentityResult result = await UserMgr.ChangePasswordAsync(user, old_password, password); if (result.Succeeded) { return(RedirectToAction("Dashboard")); } else { ViewBag.error = "Old passord is incorrect"; } return(View(user)); } if (!string.IsNullOrEmpty(UserName)) { IdentityResult result = await UserMgr.UpdateAsync(user); if (result.Succeeded) { return(RedirectToAction("Dashboard")); } else { return(View(user)); } } } else { ModelState.AddModelError("", "User Not Found"); } return(View(user)); }
private Task <User> GetCurrentUserAsync() => UserMgr.GetUserAsync(HttpContext.User);