public static async Task<SectionDisplayObject> GetSectionDisplayObject(SectionService ss, Section section) { //check to see if the item is already in cache. if so, return the cache item var cache = (SectionDisplayObject)HttpContext.Current.Cache[section.id]; if (cache != null) return cache; var courseOfferingCache = (CourseOffering)HttpContext.Current.Cache[section.courseOfferingId]; if (courseOfferingCache == null){ var courseOfferings = await GetAllCourseOfferings(ss); courseOfferingCache = courseOfferings.FirstOrDefault(co => co.id == section.courseOfferingId); } var courseCache = new Course(); if (courseOfferingCache != null) { courseCache = (Course)HttpContext.Current.Cache[courseOfferingCache.courseId]; if (courseCache == null) { var courses = await GetAllCourses(ss); courseCache = courses.FirstOrDefault(c => c.id == courseOfferingCache.courseId); } } var sdo = MapSectionToSectionDisplayObject(courseCache, section.id); HttpContext.Current.Cache.Insert(section.id, sdo); return sdo; }
private static SectionDisplayObject MapSectionToSectionDisplayObject(Course c, string sectionId) { var newSection = new SectionDisplayObject(); if (c != null) { newSection.id = sectionId; newSection.courseTitle = c.courseTitle; newSection.courseDescription = c.courseDescription; newSection.courseLevel = c.courseLevel; newSection.subjectArea = c.subjectArea; } return newSection; }