public IEnumerable <PageGrouped> GetAllByRole(int id) { var result = _context.PagesEx.AsNoTracking().FromSql("usp_GetPagesByRole_sel {0}", id). Select(pg => new PagesEx { PagesID = pg.PagesID, PageName = pg.PageName, FullPath = pg.FullPath, IsActive = pg.IsActive, PagesGroupsID = pg.PagesGroupsID, PagesGroupsName = pg.PagesGroupsName, RoleTypeID = pg.RoleTypeID, RoleTypeName = pg.RoleTypeName, PageInUserRoleID = pg.PageInUserRoleID }); var groupedresult = from so in result group so by so.PagesGroupsName into ByGroup select new PageGrouped { PageGroup = ByGroup.Key, Pages = ByGroup.ToList() }; return(groupedresult); }
public JsonResult GetPagesForUser(int id) { /* by parent * IQueryable<PagesEx> result = _context.PagesEx.FromSql(@"usp_GetPagesByUser_sel {0}", id). * Select(pg => new PagesEx * { * PagesID = pg.PagesID, * PageName = pg.PageName, * FullPath = pg.FullPath, * IsActive = pg.IsActive, * PagesGroupsID = pg.PagesGroupsID, * PagesGroupsName = pg.PagesGroupsName, * RoleTypeID = pg.RoleTypeID, * RoleTypeName = pg.RoleTypeName, * ParentGroupID = pg.ParentGroupID, * ParentGroupName = pg.ParentGroupName, * PageInUserRoleID = pg.PageInUserRoleID * }); * * var groupedresult = from so in result * group so by so.ParentGroupName into GroupedbyParent * select new * { * ParentGroup = GroupedbyParent.Key, * PageGroups = from grp2 in GroupedbyParent * group grp2 by grp2.PagesGroupsName into GroupedbyGroupName * select new * { * PageGroup = GroupedbyGroupName.Key, * Pages = GroupedbyGroupName.ToList() * } * }; */ IQueryable <PagesEx> result = _context.PagesEx.FromSql(@"usp_GetPagesByUser_sel {0}", id). Select(pg => new PagesEx { PagesID = pg.PagesID, PageName = pg.PageName, FullPath = pg.FullPath, IsActive = pg.IsActive, PagesGroupsID = pg.PagesGroupsID, PagesGroupsName = pg.PagesGroupsName, RoleTypeID = pg.RoleTypeID, RoleTypeName = pg.RoleTypeName, //ParentGroupID = null, //ParentGroupName = null, PageInUserRoleID = pg.PageInUserRoleID }); var groupedresult = from so in result group so by so.PagesGroupsName into ByGroup select new { PageGroup = ByGroup.Key, Pages = ByGroup.ToList() }; return(Json(groupedresult)); }