public ActionResult ControllerRoles(int?id) { if (!User.Identity.IsAuthenticated) { return(RedirectToRoute(new { controller = "Login", action = "Index" })); } if (Session["LoginRole"] == null) { return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限!" })); } ControllerRolesModel crModel = new ControllerRolesModel(); if (id != null) { int roleid = (int)id; var controlles = (from rvc in db.Role_vs_Controllers where rvc.rvc_role_id == id select rvc.rvc_controller ).ToArray(); crModel.roleId = roleid; StringBuilder strList = new StringBuilder(); foreach (string item in controlles) { strList.Append(item).Append(","); } crModel.hascontrollers = strList.ToString(); } List <SelectOption> options = DropDownList.GetAllControllers(); ViewData["controllers"] = DropDownList.SetDropDownList(options); options = DropDownList.SysRolesSelect(); ViewData["roles"] = DropDownList.SetDropDownList(options); return(View(crModel)); }
public ActionResult ControllerRoles(ControllerRolesModel Model) { List <SelectOption> options = DropDownList.GetAllControllers(); ViewData["controllers"] = DropDownList.SetDropDownList(options); options = DropDownList.SysRolesSelect(); ViewData["roles"] = DropDownList.SetDropDownList(options); if (!User.Identity.IsAuthenticated) { ViewBag.msg = "系统管理员权限不允许修改。"; return(View(Model)); } if (Model.roleId == 1) { return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限!" })); } var cs = db.Role_vs_Controllers.Where(x => x.rvc_role_id == Model.roleId); db.Role_vs_Controllers.RemoveRange(cs); string[] list = Model.hascontrollers.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (string citem in list) { if (string.IsNullOrEmpty(citem)) { continue; } Role_vs_Controller rcmodel = new Role_vs_Controller(); rcmodel.rvc_role_id = Model.roleId; rcmodel.rvc_controller = PageValidate.InputText(citem, 200); db.Role_vs_Controllers.Add(rcmodel); } try { db.SaveChanges(); ViewBag.msg = "添加成功。"; }catch (Exception e) { ViewBag.msg = "添加出错,请重新操作或联系管理员。"; } return(View(Model)); }