예제 #1
0
        public async Task <List <RoleAuthOutputDto> > GetRoleAuthListAsync(string roleId)
        {
            var modules = await _dal.GetAllListAsync <Module>();

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

            var rothauth = await _dal.GetAllListAsync <Authorize>(new { ObjectId = roleId, ObjectType = 1 });

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

            res = (List <Module> list, string parentid) =>
            {
                var items = list.FindAll(t => t.ParentId == parentid);

                var b = new List <RoleAuthOutputDto>();
                if (items.Count == 0)
                {
                    var buttons = moduleButtons.FindAll(t => t.ModuleId == parentid);
                    foreach (var item in buttons)
                    {
                        var isHas = rothauth.Exists(t => t.ItemId == item.Id);
                        b.Add(new RoleAuthOutputDto()
                        {
                            Id       = item.Id,
                            Title    = item.Title,
                            IsMenu   = 2,
                            Disabled = item.Enabled == 1 ? false : true,
                            Selected = isHas,
                            Checked  = isHas
                        });
                    }
                }
                else
                {
                    items.ForEach(t =>
                    {
                        bool isHas = rothauth.Exists(r => r.ItemId == t.Id);
                        b.Add(new RoleAuthOutputDto()
                        {
                            Id       = t.Id,
                            Title    = t.Title,
                            IsMenu   = t.IsMenu,
                            Disabled = t.Enabled == 1 ? false : true,
                            Selected = isHas,
                            Checked  = isHas,
                            Children = res(list, t.Id)
                        });
                    });
                }

                return(b);
            };
            return(res(modules, "0"));
        }