コード例 #1
0
        /// <summary>
        /// 获取全部 角色接口(按钮)关系数据
        /// </summary>
        /// <returns></returns>
        // [Caching(AbsoluteExpiration = 10)]
        public async Task <List <Authorize> > GetRoleModule()
        {
            var roleModulePermissions = await _moduleDAL.GetAllListAsync <Authorize>(new { ItemType = 2 });

            if (roleModulePermissions.Count > 0)
            {
                var roles = await _moduleDAL.GetAllListAsync <Role>();

                var modulebuttons = await _moduleDAL.GetAllListAsync <ModuleButton>();

                foreach (var item in roleModulePermissions)
                {
                    item.Role         = roles.Where(t => t.Id == item.ObjectId).FirstOrDefault();
                    item.ModuleButton = modulebuttons.Where(t => t.Id == item.ItemId).FirstOrDefault();
                }
            }
            return(await Task.FromResult(roleModulePermissions));
        }
コード例 #2
0
        public async Task <PageData> GetModulePageListAsync(Pagination pagination, string title)
        {
            var modules = await _moduleDAL.GetModulePageListAsync(pagination, title);

            var moduleButtons = await _moduleDAL.GetAllListAsync <ModuleButton>();

            Func <List <Module>, string, List <ModulePageOutputDto> > res = null;

            //递归0.0
            res = (List <Module> list, string parentid) =>
            {
                var items = list.FindAll(t => t.ParentId == parentid).OrderBy(t => t.OrderSort).ToList();

                var b = new List <ModulePageOutputDto>();
                //按钮
                if (items.Count == 0)
                {
                    var buttons = moduleButtons.FindAll(t => t.ModuleId == parentid);
                    foreach (var item in buttons)
                    {
                        b.Add(new ModulePageOutputDto()
                        {
                            Id          = item.Id,
                            Title       = item.Title,
                            Icon        = item.Icon,
                            Path        = item.Path,
                            Name        = item.ModuleName,
                            Api         = item.Api,
                            IsMenu      = 2,
                            OrderSort   = item.OrderSort,
                            Description = item.Description,
                            Enabled     = item.Enabled,
                            ParentId    = parentid
                        });
                    }
                }
                else //菜单
                {
                    items.ForEach(t =>
                    {
                        b.Add(new ModulePageOutputDto()
                        {
                            Id          = t.Id,
                            Title       = t.Title,
                            Icon        = t.Icon,
                            Name        = t.Title,
                            Path        = t.Path,
                            Api         = t.Api,
                            IsMenu      = t.IsMenu,
                            OrderSort   = t.OrderSort,
                            Description = t.Description,
                            Enabled     = t.Enabled,
                            ParentId    = parentid,
                            Children    = res(list, t.Id)
                        });
                    });
                }
                return(b);
            };
            var r = new PageData()
            {
                data  = res(modules.ToList(), "0"),
                total = pagination.total
            };

            return(r);
        }