public async Task<ActionResult> ChangeEmail(ChangeEmailViewModel model) { if (!ModelState.IsValid) { return View(model); } //Get the old user so we have the fields for it, then update the privacy setting and save to the DB var newUser = UserManager.FindById(User.Identity.GetUserId()); newUser.Email = model.NewEmail; var result = await UserManager.UpdateAsync(newUser); if (result.Succeeded) { var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await SignInAsync(user, isPersistent: false); } return RedirectToAction("Index", new { Message = ManageMessageId.ChangeEmailSuccess }); } AddErrors(result); return View(model); }
// // GET: /Manage/ChangeEmail public ActionResult ChangeEmail() { var userId = User.Identity.GetUserId(); var model = new ChangeEmailViewModel { OldEmail = UserManager.FindById(User.Identity.GetUserId()).Email, NewEmail = UserManager.FindById(User.Identity.GetUserId()).Email }; return View(model); }