public ActionResult EditUserRoles(EditUserRolesViewModel model) { var removedFrom = 0; var addedTo = 0; model.Roles.Remove(String.Empty); foreach (var role in Roles.GetRolesForUser(model.Username)) if (!model.Roles.Contains(role)) { removedFrom++; Roles.RemoveUserFromRole(model.Username, role); } foreach (var role in model.Roles) if (!Roles.IsUserInRole(model.Username, role)) { addedTo++; Roles.AddUserToRole(model.Username, role); } TempData["message"] = String.Format("{0} has been added to {1} roles and removed from {2}", model.Username, addedTo, removedFrom); return RedirectToAction("EditUserRoles", new { username = model.Username}); }
public ActionResult Remove(EditUserRolesViewModel model, int index) { ModelState.Clear(); model.Roles.Remove(String.Empty); model.Roles.RemoveAt(index); model.AllRoles = Roles.GetAllRoles().ToList(); return View("Form", model); }
public ActionResult EditUserRoles(string username) { var model = new EditUserRolesViewModel { Username = username, Roles = Roles.GetRolesForUser(username).ToList(), AllRoles = Roles.GetAllRoles().ToList() }; return View(model); }
public ActionResult EditUserRoles(string username) { var model = new EditUserRolesViewModel { Username = username, Roles = Roles.GetRolesForUser(username).ToList(), AllRoles = Roles.GetAllRoles().ToList()}; //var results = from role in Roles.GetAllRoles() // where !model.Roles.Contains(role) // select role; //model.AvailableRoles = (from role in results // select new SelectListItem {Text = role}).ToList(); ////model.AvailableRoles = Roles.GetAllRoles().Where(r => !model.Roles.Contains(r)).Select(r=> new SelectListItem{Text = r}).ToList(); return View(model); }
public ActionResult Add(EditUserRolesViewModel model) { model.AllRoles = Roles.GetAllRoles().ToList(); return View("Form", model); }