public ActionResult RoleAddUser(RoleModel model) { if (String.IsNullOrEmpty(model.NewUserId)) { ModelState.AddModelError("NewUserId", "The New User field is required."); } Helper.ForceValidation(ModelState, model); UserRole role = model.Role; if (ModelState.IsValid) { if (!String.IsNullOrEmpty(model.NewUserId)) { SecurityData.AddUserToRole(new Guid(model.NewUserId), role.RoleName); } return RedirectToAction("RoleAddEdit", new { @id = role.RoleId }); } Helper.HandleErrorDict(ModelState); model.LoadUsers(); return View("RoleAddEdit", model); }
public ActionResult RoleAddEdit(RoleModel model) { Helper.ForceValidation(ModelState, model); if (ModelState.IsValid) { UserRole role = model.Role; UserRole item = SecurityData.FindRole(role.RoleName); if (item == null) { item = SecurityData.FindRoleByID(role.RoleId); } if (item == null) { item = new UserRole(); item.RoleId = role.RoleId; } item.RoleName = role.RoleName.Trim(); item.Save(); return RedirectToAction("RoleAddEdit", new { @id = item.RoleId }); } Helper.HandleErrorDict(ModelState); return View(model); }
public ActionResult RoleRemoveUsers(RoleModel model) { UserRole role = model.Role; if (ModelState.IsValid) { List<UserModel> usrs = model.Users.Where(x => x.Selected).ToList(); foreach (var u in usrs) { SecurityData.RemoveUserFromRole(u.User.UserName, role.RoleName); } return RedirectToAction("RoleAddEdit", new { @id = role.RoleId }); } Helper.HandleErrorDict(ModelState); return View("RoleAddEdit", model); }
public ActionResult RoleAddEdit(string id) { RoleModel model = null; if (!String.IsNullOrEmpty(id)) { model = new RoleModel(id); } else { model = new RoleModel(); } return View(model); }