示例#1
0
        public JsonResult TreeAuthRoleNode()
        {
            var nodesBll = new NodesBll();
            var list     = nodesBll.SearchListByValid(Utits.IsSuper);

            list = list == null ? new List <Nodes>() : list.OrderBy(c => c.OrderIndex).ToList();

            IList <AuthRoleNode> mtrList = null;
            Guid roleId = RequestParameters.PGuid("roleID");

            if (roleId != Guid.Empty)
            {
                var authRoleNodeBll = new AuthRoleNodeBll();
                mtrList = authRoleNodeBll.GetListByRoleId(roleId);//角色拥有的节点权限
            }
            if (mtrList == null)
            {
                mtrList = new List <AuthRoleNode>();
            }
            var       listTree = new List <TreeModel>();
            TreeModel itemTree = null;

            foreach (var item in list)
            {
                itemTree      = new TreeModel();
                itemTree.Id   = item.NodeId;
                itemTree.Name = item.NodeName;
                itemTree.Pid  = item.ParentID;
                foreach (AuthRoleNode itemMtr in mtrList)
                {
                    if (item.NodeId == itemMtr.NodeId)
                    {
                        itemTree.Checked = true;
                        break;
                    }
                }
                //itemTree.nocheck = list.Count(c => c.ParentID == item.NodeId) > 0;
                itemTree.Checkbox = !itemTree.nocheck;
                itemTree.open     = true;
                listTree.Add(itemTree);
            }

            return(Json(listTree));
        }
示例#2
0
        public JsonResult TreeAuthRoleNodeButton()
        {
            var           nodesBll = new NodesBll();
            IList <Nodes> list     = nodesBll.SearchListByValid(Utits.IsSuper);

            if (list != null)
            {
                list = list.OrderBy(c => c.OrderIndex).ToList();
            }
            else
            {
                list = new List <Nodes>();
            }

            IList <AuthRoleNodeButton> mtrList = null;
            Guid roleId = RequestParameters.PGuid("RoleID");

            if (roleId != Guid.Empty)
            {
                var authUserNodeBll = new AuthRoleNodeButtonBll();
                mtrList = authUserNodeBll.GetListByRoleId(roleId);//该角色拥有的节点按钮权限
            }
            if (mtrList == null)
            {
                mtrList = new List <AuthRoleNodeButton>();
            }
            var                 listTree = new List <TreeModel>();
            TreeModel           itemTree;
            var                 nodeToButtonBll   = new NodeButtonBll();
            var                 listvNodeToButton = nodeToButtonBll.SearchByValid(Utits.IsSuper);
            IList <vNodeButton> listNodeToButton;
            TreeModel           itemNode;
            AuthRoleNodeButton  itemAuthRoleNodeButton;

            foreach (Nodes item in list)
            {
                itemTree          = new TreeModel();
                itemTree.Id       = item.NodeId;
                itemTree.Name     = item.NodeName;
                itemTree.Pid      = item.ParentID;
                itemTree.nocheck  = true;
                itemTree.Checkbox = !itemTree.nocheck;
                itemTree.open     = true;
                listTree.Add(itemTree);


                if (item.NodeType != -1)//表示非系统页面(节点)
                {
                    listNodeToButton = listvNodeToButton.Where(c => c.NodeId == item.NodeId).ToList();
                    foreach (var itemNtb in listNodeToButton)
                    {
                        itemNode               = new TreeModel();
                        itemNode.Id            = itemNtb.NodeButtonId + 100000;
                        itemNode.Name          = itemNtb.BtnName;
                        itemNode.Pid           = item.NodeId;
                        itemAuthRoleNodeButton = mtrList.FirstOrDefault(c => c.NodeButtonId == itemNtb.NodeButtonId);
                        if (itemAuthRoleNodeButton != null)
                        {
                            itemNode.Checked = true;
                        }
                        itemNode.nocheck  = false;
                        itemNode.Checkbox = !itemNode.nocheck;
                        itemTree.open     = true;
                        listTree.Add(itemNode);
                    }
                }
            }

            return(Json(listTree));
        }