/// <summary> /// 菜单列表转为树形结构 /// </summary> public AdminMenuConfig GetMenuConfig() { using (var dbContext = new AccountDbContext()) { var menuList = dbContext.Menus.ToList(); var value = new AdminMenuConfig(); value.AdminMenuGroups = (from a in menuList where a.ParentId == _RootMenuId orderby a.Orderby select new AdminMenuGroup { Id = a.ID.ToString(), Name = a.Name, Url = a.Url, Icon = a.Icon, Code = a.Code, Permission = a.Permission, Info = a.Info, AdminMenuArray = (from b in menuList where b.ParentId == a.ID orderby b.Orderby select new AdminMenu { Id = b.ID.ToString(), Name = b.Name, Url = b.Url, Code = b.Code, Permission = b.Permission, Info = b.Info }).ToList <AdminMenu>() }).ToArray <AdminMenuGroup>(); return(value); } }
public AdminMenuConfig GetUserMenuList(Guid token) { using (var db = new AccountDbContext()) { var loginInfo = GetLoginInfo(token); if (loginInfo == null) { throw new NullReferenceException("用户不存在"); } var menus = db.Menus.Where(o => loginInfo.BusinessPermissionList.Contains(o.ID)).ToList(); var value = new AdminMenuConfig(); value.AdminMenuGroups = (from a in menus where a.ParentId == _RootMenuId orderby a.Orderby select new AdminMenuGroup { Id = a.ID.ToString(), Name = a.Name, Url = a.Url, Icon = a.Icon, Code = a.Code, Permission = a.Permission, Info = a.Info, AdminMenuArray = (from b in menus where b.ParentId == a.ID orderby b.Orderby select new AdminMenu { Id = b.ID.ToString(), Name = b.Name, Url = b.Url, Icon = b.Icon, Code = b.Code, Permission = b.Permission, Info = b.Info }).ToList <AdminMenu>() }).ToArray <AdminMenuGroup>(); return(value); } }