Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static IQueryable<Course> QueryCoursesIncludeAll(this DbSet<Course> set)
- {
- var query = set.AsQueryable();
- query = query.Include(x => x.Exercises);
- query = query.Include(x => x.Exercises.Select(y => y.Packages));
- query = query.Include(x => x.Exercises.Select(y => y.Archive));
- query = query.Include(x => x.Exercises.Select(y => y.ProcessedExercises));
- query = query.Include(x => x.Exercises.Select(y => y.ProcessedExercises.Select(z => z.SubmittedResults)));
- query = query.Include(x => x.Packages);
- query = query.Include(x => x.Packages.Select(y => y.Exercises));
- query = query.Include(x => x.Packages.Select(y => y.Archive));
- query = query.Include(x => x.CourseArchives);
- query = query.Include(x => x.Contributors);
- query = query.Include(x => x.Owner);
- return query;
- }
- public static async Task<List<Course>> GetCoursesAsync(WebUser webUser)
- {
- using (var ctx = new DatabaseContext())
- {
- var query = ctx.Courses.QueryCoursesIncludeAll();
- if (webUser.Role != WebUserRole.Administrator)
- {
- query = query.Where(x => x.Owner.Id == webUser.Id || x.Contributors.Any(y => y.Id == webUser.Id));
- }
- return await query.ToListAsync();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement