public ActionResult Edit(string username) { MembershipUser user = Membership.GetUser(username); UserModel model = new UserModel(user); populateAssignedGroups(user); populateAssignedRoles(user); ViewBag.UsersAdminActive = true; return View(model); }
public ActionResult Edit(UserModel model, int[] selectedGroups, string[] selectedRoles) { if (selectedGroups == null) { ModelState.AddModelError("", "No groups selected for this user"); } if (selectedRoles == null) { ModelState.AddModelError("", "No roles selected for this user"); } if (ModelState.IsValid) { MembershipUser user = Membership.GetUser(model.UserName); using (TransactionScope trans = new TransactionScope()) { try { user.Email = model.Email; user.IsApproved = model.Enabled; Membership.UpdateUser(user); UserProfile profile = UserProfile.GetFor(user); profile.FirstName = model.FirstName; profile.LastName = model.LastName; db.Entry(profile).State = EntityState.Modified; updateRoles(user, selectedRoles); updateGroups(user, selectedGroups); trans.Complete(); return RedirectToAction("Edit", new { username = user.UserName }); } catch (Exception e) { ModelState.AddModelError("", e); } } } populateAssignedGroups(selectedGroups:selectedGroups); populateAssignedRoles(selectedRoles:selectedRoles); ViewBag.UsersAdminActive = true; return View(model); }