// // GET: /Users/Edit public ActionResult Edit(string Id) { MembershipUser CurrentUser = Membership.GetUser(new Guid(Id)); UserModel User = new UserModel() { UserId = CurrentUser.ProviderUserKey.ToString(), UserName = CurrentUser.UserName, Email = CurrentUser.Email }; return View(User); }
public ActionResult Edit(UserModel model) { if (ModelState.IsValid) { MembershipUser user = Membership.GetUser(new Guid(model.UserId)); Profile profile = new Profile(user); bool saveProfileSucceeded; try { saveProfileSucceeded = profile.Save(); } catch (Exception) { saveProfileSucceeded = false; } bool changePasswordSucceeded = true; if (string.IsNullOrEmpty(model.Password) && model.Password == model.ConfirmPassword) { try { changePasswordSucceeded = profile.ChangePassword(user.ResetPassword(), model.Password); } catch (Exception) { changePasswordSucceeded = false; } } if (changePasswordSucceeded && saveProfileSucceeded) { if (user.ProviderUserKey.ToString() == Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString()) FormsAuthentication.SetAuthCookie(model.UserName, true); return RedirectToAction("Index"); } else { if (!changePasswordSucceeded) ModelState.AddModelError("", "The passwords did not match."); if (!saveProfileSucceeded) ModelState.AddModelError("", "Failed to save the user."); } } return View(model); }