예제 #1
0
        public ActionResult PerAllocation()
        {
            //系统
            string sysname = "所有可操作系统";
            //用户或角色ID
            string id = Request["id"];

            //权限类型,user/role
            string tp = Request["tp"];

            string sysid = "";

            //搜索关键字
            ViewBag.Search = base.keywords;

            if (string.IsNullOrEmpty(tp))
            {
                return(Content("<script>alert('未接收到需要分配权限的类型')</script>"));
            }
            if (string.IsNullOrEmpty(id))
            {
                return(Content("<script>alert('未接收到需要分配权限的对象')</script>"));
            }

            int newid = int.Parse(id);

            //模块
            var moduleList = new List <Domain.SYS_MODULE>();


            if (tp == "role")
            {
                var Role = RoleManage.Get(p => p.ID == newid);
                var sys  = SystemManage.Get(p => p.ID == Role.FK_BELONGSYSTEM.ToString());
                sysname = sys.NAME;
                sysid   = sys.ID;

                //获取角色所属系统模块
                moduleList = this.ModuleManage.RecursiveModule(this.ModuleManage.LoadAll(p => p.FK_BELONGSYSTEM == Role.FK_BELONGSYSTEM).ToList());
            }
            else if (tp == "user")
            {
                //获取管理员可操作系统模块
                moduleList = this.ModuleManage.RecursiveModule(this.ModuleManage.LoadAll(p => CurrentUser.System_Id.Any(e => e == p.FK_BELONGSYSTEM)).ToList());
            }

            //搜索关键字
            if (!string.IsNullOrEmpty(keywords))
            {
                moduleList = moduleList.Where(p => p.NAME.Contains(keywords.ToLower())).ToList();
            }

            ViewData["ModuleList"] = JsonConverter.JsonClass(moduleList.Select(p => new { p.ID, MODULENAME = GetModuleName(p.NAME, p.LEVELS), p.ICON, p.PARENTID, p.LEVELS }));

            //获取权限
            var moduleId = moduleList.Select(p => p.ID).ToList();

            ViewData["PermissionList"] = this.PermissionManage.LoadAll(p => moduleId.Any(e => e == p.MODULEID)).ToList();

            //根据类型获取用户/角色已选中的权限
            var selectper = new List <string>();

            if (tp == "user")
            {
                selectper =
                    this.UserPermissionManage.LoadAll(p => p.FK_USERID == newid)
                    .Select(p => p.FK_PERMISSIONID)
                    .Cast <string>()
                    .ToList();
            }
            else if (tp == "role")
            {
                selectper =
                    this.RolePermissionManage.LoadAll(p => p.ROLEID == newid)
                    .Select(p => p.PERMISSIONID)
                    .Cast <string>()
                    .ToList();
            }

            ViewData["selectper"] = selectper;

            ViewData["PermissionType"] = tp;

            ViewData["objId"] = id;

            ViewData["systemName"] = sysname;

            ViewData["systemId"] = sysid;

            return(View());
        }