Exemplo n.º 1
0
        public ActionResult Left()
        {
            pbs_sys_MenuService mesMenuService = new pbs_sys_MenuService();
            pbs_sys_users       userDate       = (pbs_sys_users)Session["USER"];
            MenuModels          models         = new MenuModels();

            models.ParentItemList = new List <ParentItem>();
            if (userDate != null && !string.IsNullOrEmpty(userDate.role.ToString()))
            {
                ResultInfo <DataTable> resultPm = mesMenuService.GetThisTreeNodeMenu("#", userDate.role.ToString());
                if (resultPm.Result && resultPm.Data != null)
                {
                    foreach (DataRow prow in resultPm.Data.Rows) //得到行集合
                    {
                        ParentItem pi = new ParentItem();
                        pi.NodeId      = prow[0].ToString();
                        pi.NodeName    = prow[1].ToString();
                        pi.NodeGroup   = prow[2].ToString();
                        pi.ParentId    = prow[3].ToString();
                        pi.NodeUrl     = prow[4].ToString();
                        pi.BrotherList = new List <BrotherItem>();
                        ResultInfo <DataTable> resultBm = mesMenuService.GetThisTreeNodeMenu(pi.NodeId,
                                                                                             userDate.role.ToString());
                        if (resultBm.Result && resultBm.Data != null)
                        {
                            foreach (DataRow brow in resultBm.Data.Rows)
                            {
                                BrotherItem bi = new BrotherItem();
                                bi.NodeId       = brow[0].ToString();
                                bi.NodeName     = brow[1].ToString();
                                bi.NodeGroup    = brow[2].ToString();
                                bi.ParentId     = brow[3].ToString();
                                bi.NodeUrl      = brow[4].ToString();
                                bi.ChildrenList = new List <ChildrenItem>();
                                ResultInfo <DataTable> resultCm = mesMenuService.GetThisTreeNodeMenu(bi.NodeId,
                                                                                                     userDate.role.ToString());
                                if (resultCm.Result && resultCm.Data != null)
                                {
                                    foreach (DataRow crow in resultCm.Data.Rows)
                                    {
                                        ChildrenItem ci = new ChildrenItem();
                                        ci.NodeId    = crow[0].ToString();
                                        ci.NodeName  = crow[1].ToString();
                                        ci.NodeGroup = crow[2].ToString();
                                        ci.ParentId  = crow[3].ToString();
                                        ci.NodeUrl   = crow[4].ToString();
                                        bi.ChildrenList.Add(ci);
                                    }
                                }
                                pi.BrotherList.Add(bi);
                            }
                        }

                        models.ParentItemList.Add(pi);
                    }
                }
            }

            return(View(models));
        }
Exemplo n.º 2
0
        public Root GetTree(int roleId)
        {
            Root          root       = new Root();
            List <Parent> parentRoot = new List <Parent>();

            // 获取模块
            List <Sys_Module> moduleList = this._moduleService.GetModuleList();
            // 父节点
            List <Sys_Module> parentList = moduleList.Where(t => t.ParentId == null || t.ParentId == 0)
                                           .ToList();
            // 权限
            List <Sys_Permission>     permissionList     = this._permissionRepository.Entities(ContextDB.managerDBContext, t => 1 == 1);
            List <Sys_PermissionRole> permissionRoleList = this.GetPermissionRoleList();

            foreach (var item in parentList)
            {
                Parent parentItem = new Parent()
                {
                    name = item.Name,
                    open = true
                };
                // children
                List <Children>   childrenRoot = new List <Children>();
                List <Sys_Module> childrenList = moduleList.Where(t => t.ParentId == item.Id).ToList();
                foreach (var childItem in childrenList)
                {
                    Children children = new Children
                    {
                        name = childItem.Name
                    };

                    List <ChildrenItem>   childRoot = new List <ChildrenItem>();
                    List <Sys_Permission> pList     = permissionList.Where(t => t.ModuleId == childItem.Id).ToList();
                    foreach (var permissionItem in pList)
                    {
                        ChildrenItem childrenItem = new ChildrenItem()
                        {
                            name          = permissionItem.Name,
                            Role_Id       = roleId,
                            Permission_Id = permissionItem.Id
                        };
                        if (permissionRoleList.Where(t => t.Role_Id == roleId && t.Permission_Id == permissionItem.Id).ToList().Count > 0)
                        {
                            childrenItem.Checked = true;
                        }
                        childRoot.Add(childrenItem);
                    }

                    children.children = childRoot;
                    childrenRoot.Add(children);
                }
                parentItem.children = childrenRoot;
                parentRoot.Add(parentItem);
            }

            root.parent = parentRoot;

            return(root);
        }
Exemplo n.º 3
0
        // GET: System
        public ActionResult UserPermissions(string roleCode)
        {
            if (string.IsNullOrEmpty(roleCode))
            {
                roleCode = "1";
            }
            pbs_sys_PermissionsService permissionsService = new pbs_sys_PermissionsService();
            pbs_sys_MenuService        mesMenuService     = new pbs_sys_MenuService();
            pbs_sys_users userDate = (pbs_sys_users)Session["USER"];
            MenuModels    models   = new MenuModels();

            models.ParentItemList = new List <ParentItem>();
            if (userDate != null && !string.IsNullOrEmpty(userDate.role.ToString()))
            {
                models.UserId = userDate.id.ToString();
                ResultInfo <DataTable> resultPm = mesMenuService.GetThisTreeNodeMenu("#", userDate.role.ToString());
                if (resultPm.Result && resultPm.Data != null)
                {
                    foreach (DataRow prow in resultPm.Data.Rows) //得到行集合
                    {
                        ParentItem pi = new ParentItem();
                        pi.NodeId      = prow[0].ToString();
                        pi.NodeName    = prow[1].ToString();
                        pi.NodeGroup   = prow[2].ToString();
                        pi.ParentId    = prow[3].ToString();
                        pi.NodeUrl     = prow[4].ToString();
                        pi.BrotherList = new List <BrotherItem>();
                        ResultInfo <bool> resultExistsPi = permissionsService.ExistsPermissions(Utility.Util.ParseHelper.ToInt(roleCode),
                                                                                                prow[0].ToString(), Utility.Util.ParseHelper.ToInt(userDate.id));
                        if (resultExistsPi.Result && resultExistsPi.Data)
                        {
                            pi.IsOrNullExists = true;
                        }
                        else
                        {
                            pi.IsOrNullExists = false;
                        }
                        ResultInfo <DataTable> resultBm = mesMenuService.GetThisTreeNodeMenu(pi.NodeId,
                                                                                             userDate.role.ToString());
                        if (resultBm.Result && resultBm.Data != null)
                        {
                            foreach (DataRow brow in resultBm.Data.Rows)
                            {
                                BrotherItem bi = new BrotherItem();
                                bi.NodeId       = brow[0].ToString();
                                bi.NodeName     = brow[1].ToString();
                                bi.NodeGroup    = brow[2].ToString();
                                bi.ParentId     = brow[3].ToString();
                                bi.NodeUrl      = brow[4].ToString();
                                bi.ChildrenList = new List <ChildrenItem>();
                                ResultInfo <bool> resultExistsbi = permissionsService.ExistsPermissions(Utility.Util.ParseHelper.ToInt(roleCode),
                                                                                                        brow[0].ToString(), Utility.Util.ParseHelper.ToInt(userDate.id));
                                if (resultExistsbi.Result && resultExistsbi.Data)
                                {
                                    bi.IsOrNullExists = true;
                                }
                                else
                                {
                                    bi.IsOrNullExists = false;
                                }

                                ResultInfo <DataTable> resultCm = mesMenuService.GetThisTreeNodeMenu(bi.NodeId,
                                                                                                     userDate.role.ToString());
                                if (resultCm.Result && resultCm.Data != null)
                                {
                                    foreach (DataRow crow in resultCm.Data.Rows)
                                    {
                                        ChildrenItem ci = new ChildrenItem();
                                        ci.NodeId    = crow[0].ToString();
                                        ci.NodeName  = crow[1].ToString();
                                        ci.NodeGroup = crow[2].ToString();
                                        ci.ParentId  = crow[3].ToString();
                                        ci.NodeUrl   = crow[4].ToString();
                                        ResultInfo <bool> resultExistsci = permissionsService.ExistsPermissions(Utility.Util.ParseHelper.ToInt(roleCode),
                                                                                                                crow[0].ToString(), Utility.Util.ParseHelper.ToInt(userDate.id));
                                        if (resultExistsci.Result && resultExistsci.Data)
                                        {
                                            ci.IsOrNullExists = true;
                                        }
                                        else
                                        {
                                            ci.IsOrNullExists = false;
                                        }
                                        bi.ChildrenList.Add(ci);
                                    }
                                }
                                pi.BrotherList.Add(bi);
                            }
                        }

                        models.ParentItemList.Add(pi);
                    }
                }
            }
            models.RoleCode = roleCode;
            return(View(models));
        }