/// <summary> /// /// </summary> /// <param name="dto"></param> /// <returns></returns> public PublicResult <GetMenusByRoleApo> GetMenusByRole(GetMenusByRoleDto dto) { using (var client = DbFactory.CreateClient()) { var list = client.Queryable <RoleMenu, AdminMenu>((rm, m) => new object[] { JoinType.Left, rm.MenuId == m.Id }) .Where((rm, m) => rm.RoleId == dto.RoleId) .Select((rm, m) => new AdminMenu() { Icon = m.Icon, Id = m.Id, IsSystem = m.IsSystem, Link = m.Link, Name = m.Name, OrderIndex = m.OrderIndex, ParentId = m.ParentId }) .OrderBy("order_index ASC, id ASC") .ToList(); return(new GetMenusByRoleApo() { Menus = list }); } }
public IActionResult ConfigMenu(GetMenusByRoleDto dto) { var allMenus = _adminMenuService.PagedQueryAdminMenus(new PagedQueryAdminMenusDto() { Page = 1, PageSize = 10000 }); var getMenusByRoleResult = _roleService.GetMenusByRole(dto); if (getMenusByRoleResult.Code > 0) { return(Json(getMenusByRoleResult)); } var menusByRole = getMenusByRoleResult.Data; var configMenus = allMenus.Data.List .OrderBy(t => t.OrderIndex) .ThenBy(t => t.Id) .Select(t => new ConfigMenuItem() { id = t.Id, name = t.Name, pId = t.ParentId ?? 0, open = t.ParentId == null, @checked = menusByRole.Menus.Any(x => x.Id == t.Id) }).ToList(); var model = new ConfigMenuModel() { RoleId = dto.RoleId, Menus = configMenus }; return(View("~/Administration/Views/Role/ConfigMenu.cshtml", model)); }