Beispiel #1
0
        public async Task <IActionResult> GetTreeData(int?parentId)
        {
            var tempParentId = parentId == 0 ? null : parentId;
            var menus        = await _menuAppService.GetAllAsync(tempParentId);

            var treedata = menus.Select(a => new TreeViewModel
            {
                Id         = a.Id,
                Name       = a.Name,
                CustomData = a.Url,
                IsParent   = a.Items.Count > 0
            }).ToList();

            if (parentId == null)
            {
                var treeDataWithRoot = new TreeViewModel
                {
                    Id       = 0,
                    Name     = "菜单树",
                    Open     = true,
                    IsParent = true,
                    Children = treedata
                };
                return(Json(treeDataWithRoot));
            }

            return(Json(treedata));
        }
Beispiel #2
0
        public async Task <IActionResult> GetTreeForRoleMenu(int id)
        {
            var menus = await _menuAppService.GetAllAsync();

            var roleMenus = await _menuAppService.GetAllByRoleIdAsync(id);

            var treedata = menus.Select(a => new SimpleTreeViewModel
            {
                Id       = a.Id,
                Name     = a.Name,
                ParentId = a.ParentId,
                Checked  = roleMenus.Any(b => b.Id == a.Id)
            }).ToList();

            return(Json(treedata));
        }
Beispiel #3
0
        public async Task CreateMenu_Test()
        {
            // Act
            var menu = new MenuDto {
                Title = "Home page", Url = "www.microsoft.com"
            };

            await _menuAppService.CreateAsync(menu);

            // Assert
            var menus = await _menuAppService
                        .GetAllAsync(new Abp.Application.Services.Dto.PagedAndSortedResultRequestDto {
                MaxResultCount = 10
            });

            menus.TotalCount.ShouldBeGreaterThan(0);
        }