Beispiel #1
0
        /// <summary>
        /// 加载菜单
        /// </summary>
        /// <param name="permissonModels"></param>
        /// <returns></returns>
        public static IList <PermissionNode> BuildPermissionNodes(IList <PermissionsEntity> permissonModels)
        {
            List <PermissionNode> permissionNodeList = new List <PermissionNode>();


            // string[] ios = new string[] { "\ue622", "\ue604", "\ue63f","\ue608","\ue61d","\ue604","\ue632","\ue610" };
            // { "\ue622", "\ue604", "\ue63f", "\ue608", "\ue61d", "\ue604", "\ue632", "\ue610" };
            foreach (PermissionsEntity permissionModel1 in permissonModels.Where <PermissionsEntity>((Func <PermissionsEntity, bool>)(m => !m.ParentId.HasValue)))
            {
                PermissionsEntity tm             = permissionModel1;
                PermissionNode    permissionNode = new PermissionNode();
                permissionNode.Code = tm.PermissionCode;
                permissionNode.Text = tm.PermissionName;
                if (!string.IsNullOrEmpty(tm.IconSource))
                {
                    string ico = string.Empty;
                    if (!string.IsNullOrEmpty(permissionModel1.IconSource))
                    {
                        ico = PermissionNode.DeUnicode1(permissionModel1.IconSource);
                    }
                    permissionNode.Icon = ico;//ico;
                }
                else
                {
                    // permissionNode.Icon = ios[0];
                }

                //permissionNode.FontSize = 16;
                permissionNode.FontWeight = "Bold";



                foreach (PermissionsEntity permissionModel2 in permissonModels.Where <PermissionsEntity>((Func <PermissionsEntity, bool>)(m =>
                {
                    int?parentId = m.ParentId;
                    int permissionId = tm.PermissionId;
                    if (parentId.GetValueOrDefault() != permissionId)
                    {
                        return(false);
                    }
                    return(parentId.HasValue);
                })).ToList <PermissionsEntity>())
                {
                    permissionNode.Children.Add(new PermissionNode()
                    {
                        Code       = permissionModel2.PermissionCode,
                        Text       = permissionModel2.PermissionName,
                        Icon       = string.IsNullOrEmpty(permissionModel2.IconSource) ? " " : PermissionNode.DeUnicode1(permissionModel2.IconSource),
                        FontWeight = "Normal"
                    });
                }
                permissionNodeList.Add(permissionNode);
            }

            return((IList <PermissionNode>)permissionNodeList);
        }
        private List <PermissionNode> BuildUserPermissionNodes(IList <PermissionNode> permissionNodes)
        {
            List <PermissionNode> permissionNodeList1 = new List <PermissionNode>();

            foreach (PermissionNode permissionNode1 in (IEnumerable <PermissionNode>)permissionNodes)
            {
                List <PermissionNode> permissionNodeList2 = this.BuildUserPermissionNodes(permissionNode1.Children);
                if (permissionNodeList2.Count > 0 || string.IsNullOrEmpty(permissionNode1.Code) || this.PermissionCodes.Contains(permissionNode1.Code))
                {
                    PermissionNode permissionNode2 = new PermissionNode()
                    {
                        FontWeight = permissionNode1.FontWeight,
                        Icon       = permissionNode1.Icon,// string.IsNullOrEmpty(permissionNode1.Icon) ? " " : PermissionNode.DeUnicode1(permissionNode1.Icon),//DeUnicode1(),
                        Text       = permissionNode1.Text,
                        Code       = permissionNode1.Code,
                        Children   = (IList <PermissionNode>)permissionNodeList2
                    };
                    permissionNodeList1.Add(permissionNode2);
                }
            }
            return(permissionNodeList1);
        }
 public List <PermissionNode> GetPermissionNodesAsync()
 {
     return(this.BuildUserPermissionNodes(PermissionNode.BuildPermissionNodes(permissionsDB.GetAll <PermissionsEntity>().ToList())));
 }