public async Task<ActionResult> Edit(EditModel model) { if (string.IsNullOrEmpty(model.UserName)) { ModelState.AddModelError("UserName", "Name can't be empty!"); } if (ModelState.IsValid) { ApplicationUser user = await UserManager.FindByNameAsync(User.Identity.Name); if (user != null) { user.Email = model.Email; user.UserName = model.UserName; IdentityResult result = await UserManager.UpdateAsync(user); if (result.Succeeded) { AuthenticationManager.SignOut(); return RedirectToAction("Login", "Account"); } else { ModelState.AddModelError("", "Ooops! Something is wrong. Please, try again."); } } else { ModelState.AddModelError("", "Specified user is not found."); } return View(model); } return View(model); }
public async Task<ActionResult> Edit() { ApplicationUser user = await UserManager.FindByNameAsync(User.Identity.Name); if (user != null) { EditModel model = new EditModel { UserName = user.UserName, Email = user.Email }; return View(model); } return RedirectToAction("Login", "Account"); }