public static async Task <CourseSectionModel> GetCourseSectionsAsync( int courseId, string userId) { var db = ApplicationDbContext.Create(); var sections = await( from p in db.Courses join pi in db.courseModules on p.Id equals pi.CourseId join i in db.Modules on pi.ModuleId equals i.Id join s in db.Sections on i.SectionId equals s.Id where p.Id.Equals(courseId) orderby s.Title select new CourseSection { Id = s.Id, ModuleTypeId = i.ModuleTypeId, Title = s.Title }).ToListAsync(); var result = sections.Distinct(new CourseSectionEqualityComparer()).ToList(); var union = result.Where(r => !r.Title.ToLower().Contains("download")) .Union(result.Where(r => r.Title.ToLower().Contains("download"))); var model = new CourseSectionModel { Sections = union.ToList(), Title = await(from p in db.Courses where p.Id.Equals(courseId) select p.Title).FirstOrDefaultAsync() }; return(model); }
public async Task <ActionResult> Index(int id) { var model = new CourseSectionModel { Title = "The Title", Sections = new List <CourseSection>() }; var userId = Request.IsAuthenticated ? HttpContext.GetUserId() : null; var sections = await SectionExtensions.GetCourseSectionsAsync(id, userId); return(View(model)); }
public static async Task <CourseSectionModel> GetCourseSectionAsync(int courseId, string studentId) { var db = ApplicationDbContext.Create(); var sections = await( from p in db.courses join pi in db.courseContents on p.id equals pi.courseId join i in db.contents on pi.contentId equals i.id join s in db.sections on i.sectionId equals s.id where p.id.Equals(courseId) orderby s.name select new CourseSection { id = s.id, ItemTypeId = i.contentTypeId, Title = s.name }).ToListAsync(); foreach (var section in sections) { section.Items = await GetCourseSectionRowAsync(courseId, section.id, section.ItemTypeId, studentId); } var result = sections.Distinct(new CourseSectionEqualityComparer()).ToList(); var union = result.Where(r => !r.Title.ToLower().Contains("download")) .Union(result.Where(r => r.Title.ToLower().Contains("download"))); var model = new CourseSectionModel { Sections = union.ToList(), Title = await(from p in db.courses where p.id.Equals(courseId) select p.name).FirstOrDefaultAsync() }; return(model); }