Beispiel #1
0
        /// <summary>
        /// 获取菜单
        /// </summary>
        /// <param name="roleId">角色id</param>
        /// <returns></returns>
        public async Task <List <MenusAuthority> > GetMenusTreeByRoleId(int?roleId)
        {
            return(await Task.Run(async() =>
            {
                List <MenusModel> list;
                if (roleId != -1)
                {
                    list = await roleMenuRepository.GetRoleMenu <MenusModel>(roleId);
                }
                else
                {
                    list = await menusRepository.FindList <MenusModel>();
                }

                List <MenusAuthority> result = list
                                               .Where(u => (u.ParentId == 0 || u.ParentId == null)).OrderBy(u => u.Sort)
                                               .Select(u => new MenusAuthority()
                {
                    Id = u.Id,
                    Icon = u.Icon,
                    LinkUrl = u.LinkUrl,
                    Name = u.Name,
                    Key = u.Key,
                    Children = GetTreeData(list, u.Id, u.Name)
                }).ToList();

                result = result.Where(u => u.Children != null && u.Children.Count > 0).ToList();

                return result;
            }));
        }
Beispiel #2
0
        /// <summary>
        /// 获取角色菜单权限
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public async Task <List <MenusAuthorityTree> > GetMenusByRoleId(int roleId)
        {
            return(await Task.Run(async() =>
            {
                var menuAllList = await menusRepository.FindList <MenusModel>(string.Format(" EnableMarked='{0}'", 1));
                var roleMenuList = await roleMenuRepository.GetRoleMenu <MenusModel>(roleId);

                var result = menuAllList.Where(u => (u.ParentId == 0 || u.ParentId == null)).OrderBy(u => u.Sort)
                             .Select(i => new MenusAuthorityTree()
                {
                    Id = i.Id,
                    @Checked = roleMenuList.Where(m => m.Id == i.Id).Count() > 0 ? true : false,
                    Disabled = false,
                    Expand = true,
                    Title = i.Name,
                    Children = GetTreeData(menuAllList, roleMenuList, i.Id),
                }).ToList();

                return result;
            }));
        }