Exemple #1
0
        public async Task <IResultModel> MenuTree(string id)
        {
            var menus = await _menuRepository.GetListAsync(m => m.IsDel == false);

            var menuButtons = await _menuButtonRepository.GetListAsync(m => m.IsDel == false);

            var roleMenus = await _roleMenuRepository.GetListAsync(m => m.RoleId == id && m.MenuChecked == true && m.IsDel == false);

            var roleMenuButtons = await _rolePermissionRepository.GetListAsync(m => m.RoleId == id && m.IsDel == false);

            var all = _mapper.Map <List <RoleMenuPermissionTreeModel> >(menus);

            all.ForEach(m =>
            {
                m.Buttons = _mapper.Map <List <RoleMenuButtons> >(menuButtons.Where(b => b.MenuId == m.MenuId).OrderBy(b => b.Sort));
                m.Buttons.ForEach(t =>
                {
                    t.Checked  = roleMenuButtons.Any(r => r.PermissionCode == t.PermissionCode);
                    t.Disabled = !roleMenus.Any(o => o.MenuId == t.MenuId);
                });
            });

            var result = new RoleMenuPermissionResultModel()
            {
                Menus       = ResolveMenuTree(all, Guid.Empty.ToString("N")),
                RoleMenuIds = roleMenus.Select(m => m.MenuId).ToList()
            };

            return(ResultModel.Success(result));
        }