Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id)
        {
            var result = new List <ViewMenu>();

            var menusIenum = await _menuService.GetListByPageAsync(1, 1000);

            var RoleMenu = await _menuService.GetMenusOfRole(id, true);

            var role = await _roleService.GetByIdAsync(id);

            ViewBag.Role = role;
            //var res = await Task.WhenAll(_menuService.GetListByPageAsync(1, 100), _menuService.GetMenusOfRole(id));


            var menus = menusIenum.Select(m => new ViewMenu
            {
                Id       = m.Id,
                Name     = m.Name,
                Url      = m.Url,
                Type     = m.Type,
                ParentId = m.ParentId,
                OrderNum = m.OrderNum,
                Own      = RoleMenu.FindIndex(r => r.Id == m.Id) > -1,
            })
                        .OrderBy(m => m.Type).ThenBy(m => m.ParentId).ToList();

            foreach (var it in menus)
            {
                if (it.Type == 1)
                {
                    result.Add(it);
                    it.SubMenus = menus.Where(m => m.ParentId == it.Id)
                                  .OrderBy(m => m.OrderNum)
                                  .ToList();
                }
            }

            foreach (var it in result)
            {
                it.SubMenus.ForEach(m => m.SubMenus = menus.Where(s => s.ParentId == m.Id)
                                                      .OrderBy(s => s.OrderNum)
                                                      .ToList());
            }



            ViewBag.Menus = result.OrderBy(m => m.OrderNum).ToList();
            return(View());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取角色信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <Result <AdminRoleDto> > GetRoleAsync(long id, CancellationToken cancellationToken = default)
        {
            var res = await adminRoleService.GetByIdAsync(id, cancellationToken);

            return(RestFull.Success(data: res));
        }