Beispiel #1
0
        List <PermissionMenu> GetMenus()
        {
            List <PermissionMenu> ret = new List <PermissionMenu>();

            IUserService       userService = this.CreateService <IUserService>();
            IPermissionService authService = this.CreateService <IPermissionService>();

            Dictionary <string, SysPermission> userPermissionDic = null;

            if (!this.CurrentSession.IsAdmin)
            {
                List <SysPermission> userPermissions = userService.GetUserPermissions(this.CurrentSession.UserId);
                userPermissionDic = userPermissions.ToDictionary(a => a.Id);
            }

            List <SysPermission> permissionMenus = authService.GetPermissionMenus();

            List <SysPermission> parentPermissions = permissionMenus.Where(a => a.ParentId == null).ToList();

            foreach (SysPermission item in parentPermissions)
            {
                PermissionMenu permissionMenu = PermissionMenu.Create(item);

                List <PermissionMenu> childMenus = new List <PermissionMenu>();
                GatherChildMenus(permissionMenus, item, childMenus, userPermissionDic);

                permissionMenu.Children.AddRange(childMenus);
                ret.Add(permissionMenu);
            }

            ret = ret.Where(a => !(a.Type == PermissionType.节点组 && a.Children.Count == 0)).OrderBy(a => a.SortCode).ToList();

            return(ret);
        }
Beispiel #2
0
        List <PermissionMenu> GetMenus()
        {
            List <PermissionMenu> ret = new List <PermissionMenu>();

            IUserService       userService = this.CreateService <IUserService>();
            IPermissionService authService = this.CreateService <IPermissionService>();

            Dictionary <string, Sys_Permission> userPermissionDic = null;

            if (!this.CurrentSession.IsAdmin)
            {
                List <Sys_Permission> userPermissions = userService.GetUserPermissions(this.CurrentSession.UserId);
                userPermissionDic = userPermissions.ToDictionary(a => a.Id);
            }

            List <Sys_Permission> permissionMenus = authService.GetPermissionMenus();

            List <Sys_Permission> parentPermissions = permissionMenus.Where(a => a.ParentId == null).ToList();

            foreach (Sys_Permission item in parentPermissions)
            {
                PermissionMenu permissionMenu = PermissionMenu.Create(item);

                List <PermissionMenu> childMenus = new List <PermissionMenu>();
                GatherChildMenus(permissionMenus, item, childMenus, userPermissionDic);
                //var childPermissions = permissionMenus.Where(a => a.ParentId == item.Id);
                //foreach (Sys_Permission childPermission in childPermissions)
                //{
                //    if (!this.CurrentSession.IsAdmin)
                //    {
                //        if (childPermission.Type != PermissionType.公共菜单 && !userPermissionDic.ContainsKey(childPermission.Id))
                //            continue;
                //    }

                //    permissionMenu.Children.Add(PermissionMenu.Create(childPermission));
                //}

                permissionMenu.Children.AddRange(childMenus);
                ret.Add(permissionMenu);
            }

            //ret = ret.Where(a => a.Type != AuthType.节点组 || (a.Type == AuthType.节点组 && a.Children.Count > 0)).ToList();
            ret = ret.Where(a => !(a.Type == PermissionType.节点组 && a.Children.Count == 0)).OrderBy(a => a.SortCode).ToList();

            //foreach (var item in ret)
            //{
            //    item.Children = item.Children.ToList();
            //}

            return(ret);
        }
Beispiel #3
0
        public static PermissionMenu Create(Sys_Permission permission)
        {
            PermissionMenu ret = new PermissionMenu()
            {
                Id       = permission.Id,
                Name     = permission.Name,
                ParentId = permission.ParentId,
                Type     = permission.Type,
                Url      = permission.Url,
                Icon     = permission.Icon,
                SortCode = permission.GetSortCode(),
            };

            return(ret);
        }
Beispiel #4
0
        void GatherChildMenus(List <Sys_Permission> permissions, Sys_Permission permission, List <PermissionMenu> list, Dictionary <string, Sys_Permission> userPermissionDic)
        {
            var childPermissions = permissions.Where(a => a.ParentId == permission.Id).OrderBy(a => a.SortCode);

            foreach (Sys_Permission childPermission in childPermissions)
            {
                if (childPermission.Type == PermissionType.节点组)
                {
                    GatherChildMenus(permissions, childPermission, list, userPermissionDic);
                    continue;
                }

                if (childPermission.Type != PermissionType.公共菜单 && !this.CurrentSession.IsAdmin)
                {
                    if (!userPermissionDic.ContainsKey(childPermission.Id))
                    {
                        continue;
                    }
                }

                list.Add(PermissionMenu.Create(childPermission));
            }
        }