public ActionResult ChangeEmail(int id) { var user = GetUser(id, true); var model = new AccountChangeEmailModel { Id = id, CurrentEmail = user.Email, NewEmail = user.Email, }; return View(model); }
public ActionResult ChangeEmail(AccountChangeEmailModel model) { if (!ModelState.IsValid) return View(model); model.NewEmail = model.NewEmail.Trim(); var user = GetUser(model.Id, true); var foundUser = _repository.Find<UserProfile>().GetBy(model.NewEmail); if (foundUser != null && foundUser.Id != user.Id) { ModelState.AddModelError("NewEmail", "Invalid or taken email address."); return View(model); } if (foundUser == null) { user.UpdateEmail(model.NewEmail); _repository.Save(user); } return RedirectTo<AccountController>(c => c.Show(model.Id, user.UrlName)); }