Example #1
0
        public List <PermissionMenu> GetMenu(long roleId, string menuType = "menu")
        {
            var listAll = _client.Queryable <Sys_rolemenu, Sys_menu>
                              ((s, c) => new object[] {
                JoinType.Left, s.MenuId == c.MenuId,
            })
                          .Select((s, c) => new
            {
                RoleId = s.RoleId.ToString(),
                c.IsDel,
                c.MenuName,
                c.MenuUrl,
                c.MenuType,
                c.MenuIcon,
                c.MenuParent,
                c.Status,
                c.MenuId,
                c.Sort
            }).MergeTable().Where((s) => s.IsDel == 1 && s.MenuType == menuType && s.Status == 1 && s.RoleId == roleId.ToString()).OrderBy(s => s.Sort).ToList();
            var listParent            = listAll.Where(s => s.MenuParent == -1).ToList();
            List <PermissionMenu> ret = new List <PermissionMenu>();

            listParent.ForEach(p =>
            {
                PermissionMenu permissionMenu = PermissionMenu.Create(new Sys_menu
                {
                    MenuId     = p.MenuId,
                    Status     = p.Status,
                    MenuIcon   = p.MenuIcon,
                    MenuName   = p.MenuName,
                    MenuParent = p.MenuParent,
                    MenuType   = p.MenuType,
                    MenuUrl    = p.MenuUrl,
                });
                permissionMenu.Children = listAll
                                          .Where(c => c.MenuParent == p.MenuId)
                                          .Select(m => new PermissionMenu()
                {
                    Id       = m.MenuId.ToString(),
                    Name     = m.MenuName,
                    Icon     = m.MenuIcon,
                    Url      = m.MenuUrl,
                    ParentId = m.MenuParent.ToString()
                }).ToList();
                ret.Add(permissionMenu);
            });
            return(ret);
        }
Example #2
0
        public List <PermissionMenu> GetMenu()
        {
            var permissionMenus   = _menuServices.QueryableToList(c => c.IsDel == 1 && c.MenuType == "menu" && c.Status == 1);
            var parentPermissions = permissionMenus.Where(a => a.MenuParent == -1).ToList();
            var ret = new List <PermissionMenu>();

            parentPermissions.ForEach(p =>
            {
                PermissionMenu permissionMenu = PermissionMenu.Create(p);
                permissionMenu.Children       = permissionMenus
                                                .Where(c => c.MenuParent == p.MenuId)
                                                .Select(m => new PermissionMenu()
                {
                    Id       = m.MenuId.ToString(),
                    Name     = m.MenuName,
                    Icon     = m.MenuIcon,
                    Url      = m.MenuUrl,
                    ParentId = m.MenuParent.ToString()
                }).ToList();
                ret.Add(permissionMenu);
            });
            return(ret);
        }