public ActionResult Edit(UserEdit user, string[] userRoleCheck) { if (ModelState.IsValid) { if (webSecurity.CurrentUser.Identity.Name.Equals(user.username) || webSecurity.CurrentUser.IsInRole("Administrator")) { User userLink = Request<User>.GetAuthItemById(user.ID, "A", "B"); userLink.realName = user.realName; Request<User>.UpdateAuthItem(Request<User>.GetAuthItemById(user.ID, "A", "B"), userLink, "A", "B"); if (webSecurity.CurrentUser.IsInRole("Administrator")) { List<String> rolesList = roles.GetAllRoles().ToList(); List<string> usersRoles = roles.GetRolesForUser(user.username).ToList(); List<string> userNewRoles = userRoleCheck.ToList(); foreach (string role in rolesList) { if (usersRoles.Contains(role)) { if (!userNewRoles.Contains(role)) { roles.RemoveUserFromRole(user.username, role); } } else { if (userNewRoles.Contains(role)) { roles.AddUserToRole(user.username, role); } } } return RedirectToAction("Index"); } return RedirectToAction("Manage", "Accounts"); } } user = new UserEdit(Request<User>.GetAuthItemById(user.ID, "A", "B")); if (webSecurity.CurrentUser.IsInRole("Administrator")) { ViewBag.AllRoles = roles.GetAllRoles().ToList(); ViewBag.UserRoles = roles.GetRolesForUser(user.username).ToList(); } return View(user); }
public ActionResult Edit(int id = 0) { UserEdit user = null; if (webSecurity.CurrentUser.IsInRole("Administrator") && id > 0) { user = new UserEdit(Request<User>.GetAuthItemById(id, "A", "B")); } else { user = new UserEdit(Request<User>.GetAuthItemByName(User.Identity.Name, "A", "B")); } if (user == null) { return HttpNotFound(); } if (webSecurity.CurrentUser.IsInRole("Administrator")) { ViewBag.AllRoles = roles.GetAllRoles().ToList(); ViewBag.UserRoles = roles.GetRolesForUser(user.username).ToList(); } return View(user); }