public void GetSections_Fall2011_OnCampus_WideTimeRange() { using (OdsRepository repository = new OdsRepository()) { TimeSpan startTime = new TimeSpan(2, 55, 0); TimeSpan endTime = new TimeSpan(22, 55, 0); IList <ISectionFacet> facets = new List <ISectionFacet>(); facets.Add(new TimeFacet(startTime, endTime)); facets.Add(new ModalityFacet(ModalityFacet.Options.OnCampus)); facets.Add(new AvailabilityFacet(AvailabilityFacet.Options.All)); string subject = null; // IList<Section> sections = repository.GetSections(subject, YearQuarter.FromString("B122"), facets); IList <Section> sections = repository.GetSections(YearQuarter.FromString("B122"), facets); Assert.IsTrue(sections.Count > 0, "No sections were returned"); // make sure we have sections that fall in the specified range... int rightSectionCount = sections.Where(s => s.Offered.Where(o => (o.StartTime.HasValue && o.StartTime.Value.TimeOfDay.CompareTo(startTime) >= 0 && o.StartTime.Value.TimeOfDay.CompareTo(endTime) <= 0)).Count() > 0).Count(); Assert.IsTrue(rightSectionCount > 0, "Section records do not include start/end times in the specified range."); // ... and that we don't have any that fall outside that range int wrongSectionCount = sections.Where(s => s.Offered.Where(o => (o.StartTime.HasValue && o.StartTime.Value.TimeOfDay.CompareTo(startTime) < 0 && o.StartTime.Value.TimeOfDay.CompareTo(endTime) > 0)).Count() > 0).Count(); Assert.IsTrue(wrongSectionCount <= 0, "Found {0} sections with start/end times outside of {1} - {2}", wrongSectionCount, startTime, endTime); } }
public void CompoundWhere_Success() { using (OdsRepository repository = new OdsRepository()) { // TODO: } }
public void GetSections_SimulateClassScheduleApplication() { // Simulates actual call from Online Class Schedule application - which passes extra IList <ISectionFacet> facets = TestHelper.GetFacets(new ModalityFacet(ModalityFacet.Options.Online)); facets.Add(new TimeFacet(new TimeSpan(0, 0, 0), new TimeSpan(23, 59, 0))); facets.Add(new DaysFacet(DaysFacet.Options.All)); using (OdsRepository repository = new OdsRepository()) { YearQuarter yrq = repository.CurrentYearQuarter; string subject = TestHelper.Data.CourseSubjectOfferedEveryQuarter; IList <Section> sections = repository.GetSections(subject, yrq, facets); int count = sections.Count; Assert.IsTrue(count > 0, "No records returned."); int expectedSectionCount = _dataVerifier.GetSectionCount(string.Format("(CourseID like '{0}%' and SBCTCMisc1 like '3%' and YearQuarterID = '{1}')", subject, yrq.ID)); Assert.AreEqual(expectedSectionCount, count); int allSectionCount = _dataVerifier.GetSectionCount("not ClassID is null"); Assert.IsTrue(allSectionCount > count, "Query failed: ALL records were returned."); } }
public void GetCourses_ModalityTimes_Afternoon_Success() { using (OdsRepository repository = new OdsRepository()) { VerifyModalityTimes("12:00", "16:59", repository); } }
public void GetCourses_ModalityTimes_Evening_Success() { using (OdsRepository repository = new OdsRepository()) { VerifyModalityTimes("17:00", "23:59", repository); } }
public void GetCourses_Modality_Online_Success() { using (OdsRepository repository = new OdsRepository()) { IList <ISectionFacet> facets = TestHelper.GetFacets(new ModalityFacet(ModalityFacet.Options.Online)); IList <Course> courses = repository.GetCourses(facets); Debug.Print("==> Online course count before DISTINCT: {0}", courses.Count); int count = courses.Select(c => c.CourseID).Distinct().Count(); Debug.Print("==> Online course count after DISTINCT: {0}", count); #if DEBUG foreach (string courseid in courses.Select(c => c.CourseID).Distinct()) { Debug.Print(courseid); } #endif int expectedCount = _dataVerifier.GetCourseIDCountForSections(String.Format("SBCTCMisc1 like '3%'")); Assert.AreEqual(expectedCount, count); int allCount = _dataVerifier.GetCourseIDCountForSections("not ClassID is null"); Assert.IsTrue(allCount > count, "Online course count is not less than count of all courses."); } }
// [Ignore] // NOTE: Proper implementation requires restructuring the GetCourses() calls. See Task #16. public void CourseFootnotes_Success() { using (OdsRepository repository = new OdsRepository()) { IList <Course> courses = repository.GetCourses(); // IList<Course> courses = repository.GetCourses("engl"); Assert.IsTrue(courses.Count > 0, "No courses returned"); #if DEBUG Debug.Print("==== All courses returned ({0}) ====", courses.Count); foreach (Course course in courses) { Debug.Print("{0}", course.CourseID); } #endif IEnumerable <Course> withFootnotes = courses.Where(c => c.Footnotes.Count > 0); #if DEBUG Debug.Print("==== Courses with footnotes ({0}) ====", withFootnotes.Count()); foreach (Course course in withFootnotes) { Debug.Print("{0}\t({1})", course.CourseID, course.Footnotes.Count); } #endif int actual = withFootnotes.Count(); int expected = _dataVerifier.GetCourseCount("((FootnoteID1 IN (SELECT f.footnoteid FROM dbo.vw_Footnote f) or FootnoteID2 IN (SELECT f.FootnoteID FROM dbo.vw_Footnote f)))"); // int expected = _dataVerifier.GetCourseCount("(isnull(FootnoteID1, '') <> '' or ISNULL(FootnoteID2, '') <> '') and rtrim(left(replace(CourseID, '&', ' '), 5)) = 'engl'"); Assert.AreEqual(expected, actual); } }
public void GetSections_Fall2011_OnCampus_WideTimeRange() { using (OdsRepository repository = new OdsRepository()) { TimeSpan startTime = new TimeSpan(2, 55, 0); TimeSpan endTime = new TimeSpan(22, 55, 0); IList<ISectionFacet> facets = new List<ISectionFacet>(); facets.Add(new TimeFacet(startTime, endTime)); facets.Add(new ModalityFacet(ModalityFacet.Options.OnCampus)); facets.Add(new AvailabilityFacet(AvailabilityFacet.Options.All)); string subject = null; // IList<Section> sections = repository.GetSections(subject, YearQuarter.FromString("B122"), facets); IList<Section> sections = repository.GetSections(YearQuarter.FromString("B122"), facets); Assert.IsTrue(sections.Count > 0, "No sections were returned"); // make sure we have sections that fall in the specified range... int rightSectionCount = sections.Where(s => s.Offered.Where(o => (o.StartTime.HasValue && o.StartTime.Value.TimeOfDay.CompareTo(startTime) >= 0 && o.StartTime.Value.TimeOfDay.CompareTo(endTime) <= 0)).Count() > 0).Count(); Assert.IsTrue(rightSectionCount > 0, "Section records do not include start/end times in the specified range."); // ... and that we don't have any that fall outside that range int wrongSectionCount = sections.Where(s => s.Offered.Where(o => (o.StartTime.HasValue && o.StartTime.Value.TimeOfDay.CompareTo(startTime) < 0 && o.StartTime.Value.TimeOfDay.CompareTo(endTime) > 0)).Count() > 0).Count(); Assert.IsTrue(wrongSectionCount <= 0, "Found {0} sections with start/end times outside of {1} - {2}", wrongSectionCount, startTime, endTime); } }
public void GetSubjects() { using (OdsRepository repository = new OdsRepository()) { IList <CoursePrefix> subjects = repository.GetCourseSubjects(); Assert.IsTrue(subjects.Count > 0); } }
public void GetSubjects() { using (OdsRepository repository = new OdsRepository()) { IList<CoursePrefix> subjects = repository.GetCourseSubjects(); Assert.IsTrue(subjects.Count > 0); } }
/// <summary> /// /// </summary> /// <param name="facet"></param> /// <param name="includeQuarterFilter"></param> /// <returns></returns> static public IList <Section> GetSectionsWithFilter(ISectionFacet facet, bool includeQuarterFilter = true) { using (OdsRepository repository = new OdsRepository()) { IList <ISectionFacet> facets = GetFacets(facet, includeQuarterFilter); return(repository.GetSections(facets)); } }
public void GetSectionsByCourseID_Success() { using (OdsRepository repository = new OdsRepository()) { IList <Section> sections = repository.GetSections(CourseID.FromString("ART 101"), facetOptions: TestHelper.GetFacets()); Assert.IsTrue(sections.Count > 0); } }
public ActionResult AllClasses(string letter, string format) { using (OdsRepository repository = new OdsRepository(HttpContext)) { // TODO: Refactor the following code into its own method // after reconciling the noted differences between AllClasses() and YearQuarter() - 4/27/2012, [email protected] using (ClassScheduleDb db = new ClassScheduleDb()) { // force CoursePrefixes to load up front for Subjects (otherwise we get an error trying to load after db has been disposed) db.ContextOptions.LazyLoadingEnabled = false; IList<Subject> subjects = db.Subjects.Include("CoursePrefixes").ToList(); IList<char> subjectLetters = subjects.Select(s => s.Title.First()).Distinct().ToList(); if (letter != null) { subjects = subjects.Where(s => s.Title.StartsWith(letter, StringComparison.OrdinalIgnoreCase)).ToList(); } #if DEBUG Debug.Print("======= Subject list ======="); foreach (Subject subject in subjects) { Debug.Print("{0} ({1})", subject.Title, subject.CoursePrefixes.Select(p => p.CoursePrefixID).ToArray().Mash(", ")); } Debug.Print("===== END Subject list ====="); #endif // Construct the model AllClassesModel model = new AllClassesModel { CurrentQuarter = repository.CurrentYearQuarter, NavigationQuarters = Helpers.GetYearQuarterListForMenus(repository), Subjects = subjects.Select(s => new SubjectModel { Title = s.Title, Slug = s.Slug, CoursePrefixes = s.CoursePrefixes.Select(p => p.CoursePrefixID).ToList() }).ToList(), LettersList = subjectLetters, ViewingLetter = String.IsNullOrEmpty(letter) ? (char?)null : letter.First() }; if (format == "json") { // NOTE: AllowGet exposes the potential for JSON Hijacking (see http://haacked.com/archive/2009/06/25/json-hijacking.aspx) // but is not an issue here because we are receiving and returning public (e.g. non-sensitive) data return Json(model, JsonRequestBehavior.AllowGet); } // set up all the ancillary data we'll need to display the View SetCommonViewBagVars(repository, string.Empty, letter); ViewBag.LinkParams = Helpers.getLinkParams(Request); return View(model); } } }
public void GetCourses_VerifyCommonCourseCharacterRemovedFromCourseID() { using (OdsRepository repository = new OdsRepository()) { IList<Course> courses = repository.GetCourses("CHEM"); int count = courses.Where(s => s.CourseID.Contains("&")).Count(); Assert.IsTrue(count == 0, "{0} records found to still contain the CCN character ('&') in the CourseID", count); } }
private OdsRepositoryTestContext() { OdsSettings = new OdsSettings { ApiBaseUrl = "https://fakeodsserver.net/ORD/2-0-0", BuyerOrganisationRoleIds = new[] { "RO98", "RO177", "RO213", "RO272" } }; OdsRepository = new OdsRepository(OdsSettings); }
public void GetCourses_VerifyCommonCourseCharacterRemovedFromCourseID() { using (OdsRepository repository = new OdsRepository()) { IList <Course> courses = repository.GetCourses("CHEM"); int count = courses.Where(s => s.CourseID.Contains("&")).Count(); Assert.IsTrue(count == 0, "{0} records found to still contain the CCN character ('&') in the CourseID", count); } }
/// <summary> /// /// </summary> /// <param name="subject"></param> private void AssertCourseCount(string subject) { using (OdsRepository repository = new OdsRepository()) { IList <Course> courses = repository.GetCourses(subject); Assert.IsTrue(courses.Count > 0, "No records were returned for '{0}'!", subject); AssertCourseCount(courses, string.Format("rtrim(LEFT(CourseID, 5)) = '{0}'", subject)); } }
public void GetCourses_VerifyCcnFlag_False() { using (OdsRepository repository = new OdsRepository()) { IList <Course> courses = repository.GetCourses(); Course course = courses.Where(s => !(s.Subject.EndsWith("&"))).Take(1).Single(); Assert.IsFalse(course.IsCommonCourse); } }
public void GetCourses_VerifyCcnFlag_True() { using (OdsRepository repository = new OdsRepository()) { IList <Course> courses = repository.GetCourses(); int expectedCount = _dataVerifier.GetCourseCount("CourseID like '%&%'"); Assert.AreEqual(expectedCount, courses.Where(c => c.IsCommonCourse).Count()); } }
public void GetSections_VerifyCommonCourseCharacterRemovedFromCourseID() { using (OdsRepository repository = new OdsRepository()) { IList <Section> sections = repository.GetSections("ENGL", YearQuarter.FromString("B122")); int count = sections.Where(s => s.CourseID.Contains("&")).Count(); Assert.IsTrue(count == 0, "{0} records found to still contain the CCN character ('&') in the CourseID", count); } }
public void GetSectionsByCourseID_WithYrq_Success() { using (OdsRepository repository = new OdsRepository()) { YearQuarter yrq = YearQuarter.FromString("B012"); IList <Section> sections = repository.GetSections(CourseID.FromString("ART 101"), yrq); Assert.IsTrue(sections.Count > 0); } }
/// <summary> /// /// </summary> /// <param name="subject"></param> /// <param name="number"></param> private void AssertCourseCount(string subject, string number) { using (OdsRepository repository = new OdsRepository()) { ICourseID courseID = CourseID.FromString(subject, number); IList <Course> courses = repository.GetCourses(courseID); Assert.IsTrue(courses.Count > 0, "No records were returned for '{0} {1}'!", subject, number); AssertCourseCount(courses, string.Format("rtrim(LEFT(CourseID, 5)) = '{0}' and LTRIM(RTRIM(SUBSTRING(CourseID, 6, 5))) = '{1}'", subject, number)); } }
public void GetCourses_Success() { int count; using (OdsRepository repository = new OdsRepository()) { count = repository.GetCourses().Count(); } Assert.IsTrue(count > 0); }
public void CurrentYearQuarter_Success() { using (OdsRepository repository = new OdsRepository()) { YearQuarter actual = repository.CurrentYearQuarter; string expected = _dataVerifier.CurrentYrq; Assert.AreEqual(expected, actual.ID); } }
public void GetSubjectsWithYQ_Success() { using (OdsRepository repo = new OdsRepository()) { YearQuarter yearQuarter = repo.CurrentYearQuarter; IList <CoursePrefix> actual = repo.GetCourseSubjects(yearQuarter); int expectedCount = _dataVerifier.GetCourseSubjectCountForSections(string.Format("YearQuarterID = '{0}'", yearQuarter.ID), true); Assert.AreEqual(expectedCount, actual.Count); } }
public void GetSectionsBySubject_WithQuarterFilter_Success() { using (OdsRepository repository = new OdsRepository()) { YearQuarter yrq = YearQuarter.FromString("B122"); IList <Section> sections = repository.GetSections("ENGL", yrq); int count = sections.Where(s => s.Yrq.ID == "B122" && s.CourseID.StartsWith("ENGL")).Count(); Assert.AreEqual(sections.Count, count); } }
public void GetSections_VerifyCourseDescriptions() { using (OdsRepository repository = new OdsRepository()) { IList <Section> sections = repository.GetSections(TestHelper.GetFacets()); Assert.IsTrue(sections.Count > 0); IEnumerable <Section> withNonNullDesc = sections.Where(s => s.CourseDescriptions != null && s.CourseDescriptions.Count > 0); Assert.IsTrue(withNonNullDesc.Count() > 0, "All CourseDescriptions properties are null"); } }
/// <summary> /// /// </summary> /// <param name="excludedSection"></param> private void AssertExcludedSection(string excludedSection) { using (OdsRepository repository = new OdsRepository()) { IList <Section> sections = repository.GetSections(TestHelper.GetFacets()); Assert.IsTrue(sections.Count > 0, "No Sections were returned."); int count = sections.Where(s => s.ID.ToString() == excludedSection).Count(); Assert.IsTrue(count <= 0, "Sections collection contains a record that should be filtered out: ({0})", excludedSection); } }
public void GetFutureQuarters() { using (OdsRepository repository = new OdsRepository()) { IList <YearQuarter> yrqList = repository.GetFutureQuarters(); int listCount = yrqList.Count; Assert.IsTrue(listCount == 1, "Returned {0} items, expected 1", listCount); // NOTE: test does not yet account for SUMMER/FALL overlapping registration period Assert.AreEqual(repository.CurrentYearQuarter.ID, yrqList[0].ID, "The quarter returned is not the current quarter."); } }
private OdsRepositoryTestContext() { OdsSettings = new OdsSettings { ApiBaseUrl = "https://fakeodsserver.net/ORD/2-0-0", BuyerOrganisationRoleIds = new[] { "RO98", "RO177", "RO213", "RO272" }, }; CachingService.DefaultCacheProvider.Value.Remove("XYZ"); OdsRepository = new OdsRepository(OdsSettings, new CachingService()); }
public void GetSections_ByClassIDCollection_Success() { int sectionCount = 3; IList <ISectionID> ids = _dataVerifier.GetSectionIDListFromQuery("english", sectionCount); using (OdsRepository repository = new OdsRepository()) { IList <Section> sections = repository.GetSections(ids, TestHelper.GetFacets()); Assert.AreEqual(sectionCount, sections.Count); } }
public void GetSections_VerifyWaitlist() { using (OdsRepository repository = new OdsRepository()) { IList <Section> sections = repository.GetSections(TestHelper.GetFacets()); int actualSectionCount = sections.Where(s => s.WaitlistCount > 0).Count(); int expectedSectionCount = _dataVerifier.GetSectionCount("ClassID in (select w.ClassID from vw_Waitlist w where w.[Status] = 'W-LISTED')"); Assert.AreEqual(expectedSectionCount, actualSectionCount); } }
[Ignore] // specific research, not part of the standard test suite public void Research() { using (OdsRepository repository = new OdsRepository()) { string courseId = "CEO 196"; IList <Course> courses = repository.GetCourses(CourseID.FromString(courseId)); Assert.IsTrue(courses.Count > 0); var foo = courses.Select(c => c.CourseID); Assert.AreEqual(courses.Count, courses.Count(c => c.CourseID == courseId)); } }
public void GetRegistrationQuarters() { using (OdsRepository repository = new OdsRepository()) { IList <YearQuarter> yrqList = repository.GetRegistrationQuarters(); int listCount = yrqList.Count; Assert.IsTrue(listCount == 1, "Returned {0} items, expected 1", listCount); // NOTE: test does not yet account for SUMMER/FALL overlapping registration period // TODO: Assert first item in list is current YRQ } }
public void ForCourseID_CurrentRegistrationQuarter() { using (OdsRepository repository = new OdsRepository()) { ICourseID courseID = CourseID.FromString("ACCT 101"); YearQuarter yrq = repository.CurrentRegistrationQuarter; int sectionCount = repository.SectionCountForCourse(courseID, yrq, TestHelper.GetFacets(false)); Assert.IsTrue(sectionCount > 0, string.Format("No sections found for '{0}' in '{1}'", courseID, yrq.FriendlyName)); int expectedCount = _dataVerifier.GetSectionCount(string.Format("YearQuarterID = '{0}' AND CourseID LIKE '{1}%{2}' AND NOT CourseID LIKE '%&%'", yrq, courseID.Subject, courseID.Number)); Assert.AreEqual(expectedCount, sectionCount); } }
public void RetrievingPresentAndFutureDescriptions() { using (OdsRepository ods = new OdsRepository()) { ICourseID courseID = CourseID.FromString("ECON&201"); IList<CourseDescription> descs = ods.GetCourseDescription(courseID, YearQuarter.FromString("B234")); Assert.IsNotNull(descs); foreach (CourseDescription desc in descs) { Console.Out.WriteLine("[{0}] {1}", desc.YearQuarterBegin, desc.Description); } Assert.IsTrue(descs.Count > 1, "ECON& 201 should have 2 descriptions, but only has {0}", descs.Count); } }
/// <summary> /// /// </summary> /// <param name="yearQuarter"></param> /// <returns></returns> public static IList<ScheduleCoursePrefix> GetSubjectList(string yearQuarter) { IList<ScheduleCoursePrefix> subjectList; using (OdsRepository db = new OdsRepository()) { IList<CoursePrefix> data; data = string.IsNullOrWhiteSpace(yearQuarter) || yearQuarter.Equals("All", StringComparison.OrdinalIgnoreCase) ? db.GetCourseSubjects() : db.GetCourseSubjects(YearQuarter.FromFriendlyName(yearQuarter)); IList<string> apiSubjects = data.Select(s => s.Subject).ToList(); using (ClassScheduleDb classScheduleDb = new ClassScheduleDb()) { // Entity Framework doesn't support all the functionality that LINQ does, so first grab the records from the database... var dbSubjects = (from s in classScheduleDb.Subjects join p in classScheduleDb.SubjectsCoursePrefixes on s.SubjectID equals p.SubjectID select new { s.Slug, p.CoursePrefixID, s.Title }) .ToList(); // ...then apply the necessary filtering (e.g. TrimEnd() - which isn't fully supported by EF subjectList = (from s in dbSubjects // TODO: replace hard-coded '&' with CommonCourseChar from .config where apiSubjects.Contains(s.CoursePrefixID.TrimEnd('&')) select new ScheduleCoursePrefix { Slug = s.Slug, Subject = s.CoursePrefixID, Title = s.Title }) .OrderBy(s => s.Title) .Distinct() .ToList(); } } return subjectList; }
public FileResult Export(String YearQuarterID) { if (HttpContext.User.Identity.IsAuthenticated == true) { // Determine whether to use a specific Year Quarter, or the current Year Quarter YearQuarter yrq; if (String.IsNullOrEmpty(YearQuarterID)) { using (OdsRepository _db = new OdsRepository()) { yrq = _db.CurrentYearQuarter; } } else { yrq = YearQuarter.FromString(YearQuarterID); } // Return all the Class Schedule Data as a file return ClassScheduleExporter.GetFile(yrq); } throw new UnauthorizedAccessException("You do not have sufficient privileges to export course data."); }
public ActionResult ClassEdit(string CourseNumber, string Subject, bool IsCommonCourse) { if (HttpContext.User.Identity.IsAuthenticated) { string fullCourseId = Helpers.BuildCourseID(CourseNumber, Subject, IsCommonCourse); ICourseID courseID = CourseID.FromString(fullCourseId); CourseMeta itemToUpdate = null; var hpFootnotes = string.Empty; string courseTitle = string.Empty; using (ClassScheduleDb db = new ClassScheduleDb()) { if(db.CourseMetas.Any(s => s.CourseID.Trim().ToUpper() == fullCourseId.ToUpper())) { //itemToUpdate = db.CourseFootnotes.Single(s => s.CourseID.Substring(0, 5).Trim().ToUpper() == subject.Trim().ToUpper() && // s.CourseID.Trim().EndsWith(courseID.Number) itemToUpdate = db.CourseMetas.Single(s => s.CourseID.Trim().ToUpper() == fullCourseId.ToUpper()); } using (OdsRepository repository = new OdsRepository()) { try { IList<Course> coursesEnum = repository.GetCourses(courseID); foreach (Course course in coursesEnum) { hpFootnotes = course.Footnotes.ToArray().Mash(" "); // BUG: If more than one course is returned from the API, this will ignore all Titles except for the last one courseTitle = course.Title; } } catch(InvalidOperationException ex) { _log.Warn(m => m("Ignoring Exception while attempting to retrieve footnote and title data for CourseID '{0}'\n{1}", courseID, ex)); } } ClassFootnote localClass = new ClassFootnote(); localClass.CourseID = MvcApplication.SafePropertyToString(itemToUpdate, "CourseID", fullCourseId); localClass.Footnote = MvcApplication.SafePropertyToString(itemToUpdate, "Footnote", string.Empty); localClass.HPFootnote = hpFootnotes; localClass.LastUpdated = MvcApplication.SafePropertyToString(itemToUpdate, "LastUpdated", string.Empty); localClass.LastUpdatedBy = MvcApplication.SafePropertyToString(itemToUpdate, "LastUpdatedBy", string.Empty); localClass.CourseTitle = courseTitle; return PartialView(localClass); } } return PartialView(); }
public JsonResult CrossListedCourses(string courseID, string yearQuarterID) { // TODO: Validate incoming yearQuarterID value // see https://github.com/BellevueCollege/CtcApi/issues/8 if (yearQuarterID.Length != 4) { _log.Error(m => m("An invalid YearQuarterID was provided for looking up cross-listed sections: '{0}'", yearQuarterID)); } else { using (ClassScheduleDb db = new ClassScheduleDb()) { string[] classIDs = (from c in db.SectionCourseCrosslistings where c.CourseID == courseID && c.ClassID.EndsWith(yearQuarterID) select c.ClassID).ToArray(); if (!classIDs.Any()) { _log.Warn(m => m("No cross-listed Sections were found for Course '{0}' in '{1}'", courseID, yearQuarterID)); } else { int count = classIDs.Count(); _log.Trace(m => m("{0} cross-listed sections found for '{1}': [{2}]", count, courseID, classIDs.Mash())); // HACK: SectionID constructors are currently protected, so we have to manually create them IList<ISectionID> sectionIDs = new List<ISectionID>(count); foreach (string id in classIDs) { sectionIDs.Add(SectionID.FromString(id)); } // write a warning to the log if we've got too many courses cross-listed with this section if (_log.IsWarnEnabled && sectionIDs.Count > MAX_COURSE_CROSSLIST_WARNING_THRESHOLD) { _log.Warn(m => m("Cross-listing logic assumes a very small number of Sections will be cross-listed with any given Course, but is now being asked to process {0} Sections for '{1}'. (This warning triggers when more than {2} are detected.)", sectionIDs.Count, courseID, MAX_COURSE_CROSSLIST_WARNING_THRESHOLD)); } using (OdsRepository ods = new OdsRepository()) { IList<Section> odsSections = ods.GetSections(sectionIDs); IList<SectionWithSeats> classScheduleSections = Helpers.GetSectionsWithSeats(yearQuarterID, odsSections.ToList(), db); IList<CrossListedCourseModel> crosslistings = (from c in classScheduleSections select new CrossListedCourseModel { // BUG: API doesn't property notify CourseID in derived class CourseID = CourseID.FromString(c.CourseID), SectionID = c.ID, // HACK: Remove IsCommonCourse property when API is fixed (see above) IsCommonCourse = c.IsCommonCourse, Credits = c.Credits, IsVariableCredits = c.IsVariableCredits, Title = c.CourseTitle }).ToList(); // NOTE: AllowGet exposes the potential for JSON Hijacking (see http://haacked.com/archive/2009/06/25/json-hijacking.aspx) // but is not an issue here because we are receiving and returning public (e.g. non-sensitive) data return Json(crosslistings, JsonRequestBehavior.AllowGet); } } } } return Json(null, JsonRequestBehavior.AllowGet); }
public void GetSectionsByCourseID_Success() { using (OdsRepository repository = new OdsRepository()) { IList<Section> sections = repository.GetSections(CourseID.FromString("ART 101"), facetOptions: TestHelper.GetFacets()); Assert.IsTrue(sections.Count > 0); } }
public void CourseFootnotes_Success() { using (OdsRepository repository = new OdsRepository()) { IList<Course> courses = repository.GetCourses(); // IList<Course> courses = repository.GetCourses("engl"); Assert.IsTrue(courses.Count > 0, "No courses returned"); #if DEBUG Debug.Print("==== All courses returned ({0}) ====", courses.Count); foreach (Course course in courses) { Debug.Print("{0}", course.CourseID); } #endif IEnumerable<Course> withFootnotes = courses.Where(c => c.Footnotes.Count > 0); #if DEBUG Debug.Print("==== Courses with footnotes ({0}) ====", withFootnotes.Count()); foreach (Course course in withFootnotes) { Debug.Print("{0}\t({1})", course.CourseID, course.Footnotes.Count); } #endif int actual = withFootnotes.Count(); int expected = _dataVerifier.GetCourseCount("((FootnoteID1 IN (SELECT f.footnoteid FROM dbo.vw_Footnote f) or FootnoteID2 IN (SELECT f.FootnoteID FROM dbo.vw_Footnote f)))"); // int expected = _dataVerifier.GetCourseCount("(isnull(FootnoteID1, '') <> '' or ISNULL(FootnoteID2, '') <> '') and rtrim(left(replace(CourseID, '&', ' '), 5)) = 'engl'"); Assert.AreEqual(expected, actual); } }
public ActionResult Subject(string Subject, string format) { using (OdsRepository repository = new OdsRepository(HttpContext)) { SubjectInfoResult subject = SubjectInfo.GetSubjectInfo(Subject); IList<string> prefixes = subject.CoursePrefixes.Select(p => p.CoursePrefixID).ToList(); IEnumerable<Course> coursesEnum = (prefixes.Count > 0 ? repository.GetCourses(prefixes) : repository.GetCourses()) .Distinct() .OrderBy(c => c.Subject) .ThenBy(c => c.Number); // TODO: Utilize SubjectModel in SubjectViewModel SubjectViewModel model = new SubjectViewModel { Courses = coursesEnum, Slug = subject.Subject.Slug, SubjectTitle = subject.Subject.Title, SubjectIntro = subject.Subject.Intro, DepartmentTitle = subject.Department.Title, DepartmentURL = subject.Department.URL, CurrentQuarter = repository.CurrentYearQuarter, NavigationQuarters = Helpers.GetYearQuarterListForMenus(repository) }; if (format == "json") { // NOTE: AllowGet exposes the potential for JSON Hijacking (see http://haacked.com/archive/2009/06/25/json-hijacking.aspx) // but is not an issue here because we are receiving and returning public (e.g. non-sensitive) data return Json(model, JsonRequestBehavior.AllowGet); } ViewBag.LinkParams = Helpers.getLinkParams(Request); SetCommonViewBagVars(repository, string.Empty, string.Empty); return View(model); } }
public void GetSubjects_VerifyCourseSubjectIsCorrectlyExcluded() { YearQuarter yrq = TestHelper.Data.YearQuarterWithSections; using (OdsRepository repo = new OdsRepository()) { IList<CoursePrefix> actual = repo.GetCourseSubjects(yrq); Assert.IsTrue(actual.Count > 0, "No subjects were returned for {0} ({1})", yrq.FriendlyName, yrq); string subject = _dataVerifier.GetRandomCourseSubject(string.Format("YearQuarterID <> '{0}'", yrq.ID), true); IEnumerable<CoursePrefix> shouldBeEmpty = actual.Where(s => s.Subject.ToUpper() == subject.ToUpper()); int emptyCount = shouldBeEmpty.Count(); if (emptyCount > 0) { Assert.Fail("{0} found in {1} ({2})", emptyCount, yrq.FriendlyName, yrq); } } }
public ActionResult YearQuarterSubject(String YearQuarter, string Subject, string timestart, string timeend, string day_su, string day_m, string day_t, string day_w, string day_th, string day_f, string day_s, string f_oncampus, string f_online, string f_hybrid, string avail, string latestart, string numcredits, string format) { IList<ISectionFacet> facets = Helpers.addFacets(timestart, timeend, day_su, day_m, day_t, day_w, day_th, day_f, day_s, f_oncampus, f_online, f_hybrid, avail, latestart, numcredits); using (OdsRepository repository = new OdsRepository()) { YearQuarter yrq = Helpers.DetermineRegistrationQuarter(YearQuarter, repository.CurrentRegistrationQuarter, RouteData); // Get the courses to display on the View IList<Section> sections; using (_profiler.Step("ODSAPI::GetSections()")) { IList<string> prefixes = SubjectInfo.GetSubjectPrefixes(Subject); sections = repository.GetSections(prefixes, yrq, facets); } #if DEBUG /* COMMENT THIS LINE FOR DEBUGGING/TROUBLESHOOTING Debug.Print("==> sections"); string zItemNum = "1230", zYrq = "B234"; // ENGL 266 if (sections.Any(s => s.ID.ItemNumber == zItemNum && s.ID.YearQuarter == zYrq)) { Section foo = sections.Where(s => s.ID.ItemNumber == zItemNum && s.ID.YearQuarter == zYrq).First(); Debug.Print("\n{0} - {1} {2}\t(Linked to: {3})", foo.ID, foo.CourseID, foo.CourseTitle, foo.LinkedTo); } else { Debug.Print("ClassID '{0}{1}' not found.", zItemNum, zYrq); } // */ #endif IList<SectionsBlock> courseBlocks; using (ClassScheduleDb db = new ClassScheduleDb()) { IList<SectionWithSeats> sectionsEnum; using (_profiler.Step("Getting app-specific Section records from DB")) { sectionsEnum = Helpers.GetSectionsWithSeats(yrq.ID, sections, db); } #if DEBUG /* COMMENT THIS LINE FOR DEBUGGING/TROUBLESHOOTING Debug.Print("==> sectionsEnum"); // string zItemNum, zYrq; zItemNum = "1230"; zYrq = "B234"; // ENGL 266 if (sectionsEnum.Any(s => s.ID.ItemNumber == zItemNum && s.ID.YearQuarter == zYrq)) { SectionWithSeats foo = sectionsEnum.Where(s => s.ID.ItemNumber == zItemNum && s.ID.YearQuarter == zYrq).First(); Debug.Print("\n{0} - {1} {2}\t(Linked to: {3})", foo.ID, foo.CourseID, foo.CourseTitle, foo.LinkedTo); } else { Debug.Print("ClassID '{0}{1}' not found.", zItemNum, zYrq); } // */ /* COMMENT THIS LINE FOR DEBUGGING/TROUBLESHOOTING IEnumerable<SectionWithSeats> s1 = sectionsEnum.Where(s => s.CourseSubject == "ENGL" && s.CourseNumber == "239"); // */ #endif courseBlocks = Helpers.GroupSectionsIntoBlocks(sectionsEnum, db); } // Construct the model SubjectInfoResult subject = SubjectInfo.GetSubjectInfoFromPrefix(Subject); IList<YearQuarter> yrqRange = Helpers.GetYearQuarterListForMenus(repository); YearQuarterSubjectModel model = new YearQuarterSubjectModel { Courses = courseBlocks, CurrentQuarter = repository.CurrentYearQuarter, CurrentRegistrationQuarter = yrqRange[0], NavigationQuarters = yrqRange, ViewingQuarter = yrq, // if we were unable to determine a Slug, use the Subject (e.g. Prefix) that brought us here Slug = subject != null ? subject.Subject.Slug : Subject, SubjectTitle = subject != null ? subject.Subject.Title : string.Empty, SubjectIntro = subject != null ? subject.Subject.Intro : string.Empty, DepartmentTitle = subject != null ? subject.Department.Title : string.Empty, DepartmentURL = subject != null ? subject.Department.URL : string.Empty, }; if (format == "json") { // NOTE: AllowGet exposes the potential for JSON Hijacking (see http://haacked.com/archive/2009/06/25/json-hijacking.aspx) // but is not an issue here because we are receiving and returning public (e.g. non-sensitive) data return Json(model, JsonRequestBehavior.AllowGet); } // set up all the ancillary data we'll need to display the View ViewBag.timestart = timestart; ViewBag.timeend = timeend; ViewBag.avail = avail; ViewBag.latestart = latestart; ViewBag.Modality = Helpers.ConstructModalityList(f_oncampus, f_online, f_hybrid); ViewBag.Days = Helpers.ConstructDaysList(day_su, day_m, day_t, day_w, day_th, day_f, day_s); ViewBag.LinkParams = Helpers.getLinkParams(Request); SetCommonViewBagVars(repository, avail, string.Empty); // TODO: Add query string info (e.g. facets) to the routeValues dictionary so we can pass it all as one chunk. IDictionary<string, object> routeValues = new Dictionary<string, object>(3); routeValues.Add("YearQuarterID", YearQuarter); ViewBag.RouteValues = routeValues; return View(model); } }
public void GetSubjectsWithChar() { using (OdsRepository repository = new OdsRepository()) { char firstChar = 'b'; IList<CoursePrefix> actual = repository.GetCourseSubjects(firstChar); int actualCount = actual.Count; Assert.IsTrue(actualCount > 0); int count = actual.Where(c => c.Subject.StartsWith(firstChar.ToString(), true, CultureInfo.CurrentCulture)).Count(); Assert.AreEqual(actualCount, count); } }
/// <summary> /// Sets all of the common ViewBag variables /// </summary> private void SetCommonViewBagVars(OdsRepository repository, string avail, string letter) { ViewBag.ErrorMsg = string.Empty; ViewBag.CurrentYearQuarter = repository.CurrentYearQuarter; ViewBag.letter = letter; ViewBag.avail = string.IsNullOrWhiteSpace(avail) ? "all" : avail; }
/// <summary> /// Gets the <see cref="YearQuarter"/> for the current, and previous 3 quarters. /// This drives the dynamic YRQ navigation bar /// </summary> public static IList<YearQuarter> GetYearQuarterListForMenus(OdsRepository repository) { IList<YearQuarter> currentFutureQuarters = repository.GetRegistrationQuarters(4); return currentFutureQuarters; }
/// <summary> /// /// </summary> /// <param name="excludedSection"></param> private void AssertExcludedSection(string excludedSection) { using (OdsRepository repository = new OdsRepository()) { IList<Section> sections = repository.GetSections(TestHelper.GetFacets()); Assert.IsTrue(sections.Count > 0, "No Sections were returned."); int count = sections.Where(s => s.ID.ToString() == excludedSection).Count(); Assert.IsTrue(count <= 0, "Sections collection contains a record that should be filtered out: ({0})", excludedSection); } }
public void GetSubjectsWithYQ_Success() { using (OdsRepository repo = new OdsRepository()) { YearQuarter yearQuarter = repo.CurrentYearQuarter; IList<CoursePrefix> actual = repo.GetCourseSubjects(yearQuarter); int expectedCount = _dataVerifier.GetCourseSubjectCountForSections(string.Format("YearQuarterID = '{0}'", yearQuarter.ID), true); Assert.AreEqual(expectedCount, actual.Count); } }
/// <summary> /// /// </summary> /// <param name="start"></param> /// <param name="end"></param> private void VerifyTimeFacet(string start, string end) { using (OdsRepository repository = new OdsRepository()) { TimeSpan startTime = TimeSpan.Parse(start); TimeSpan endTime = TimeSpan.Parse(end); IList<ISectionFacet> facets = TestHelper.GetFacets(new TimeFacet(startTime, endTime)); IList<Section> sections = repository.GetSections(facetOptions: facets); Assert.IsTrue(sections.Count > 0, "No sections were returned"); // make sure we have sections that fall in the specified range... int rightSectionCount = sections.Where(s => s.Offered.Where(o => (o.StartTime.HasValue && o.StartTime.Value.TimeOfDay.CompareTo(startTime) >= 0 && o.StartTime.Value.TimeOfDay.CompareTo(endTime) <= 0)).Count() > 0).Count(); Assert.IsTrue(rightSectionCount > 0, "Section records do not include start/end times in the specified range."); // ... and that we don't have any that fall outside that range int wrongSectionCount = sections.Where(s => s.Offered.Where(o => (o.StartTime.HasValue && o.StartTime.Value.TimeOfDay.CompareTo(startTime) < 0 && o.StartTime.Value.TimeOfDay.CompareTo(endTime) > 0)).Count() > 0).Count(); Assert.IsTrue(wrongSectionCount <= 0, "Found {0} sections with start/end times outside of {1} - {2}", wrongSectionCount, startTime, endTime); } }
public void GetSubjectsWithYrq_Modality_Online_Success() { using (OdsRepository repo = new OdsRepository()) { YearQuarter yearQuarter = YearQuarter.FromString("B122"); IList<ISectionFacet> facets = new List<ISectionFacet>(); facets.Add(new ModalityFacet(ModalityFacet.Options.Online)); IList<CoursePrefix> actual = repo.GetCourseSubjects(yearQuarter, facets); int expectedCount = _dataVerifier.GetCourseSubjectCountForSections(string.Format("YearQuarterID = '{0}' and SBCTCMisc1 like '3%'", yearQuarter.ID), true); Assert.AreEqual(expectedCount, actual.Count); int allCount = _dataVerifier.GetCourseSubjectCountForSections(string.Format("YearQuarterID = '{0}'", yearQuarter.ID)); Assert.IsTrue(allCount > actual.Count, "Count of online sections is not less than all sections"); } }
public ActionResult YearQuarter(String YearQuarter, string timestart, string timeend, string day_su, string day_m, string day_t, string day_w, string day_th, string day_f, string day_s, string f_oncampus, string f_online, string f_hybrid, string avail, string letter, string latestart, string numcredits, string format) { _log.Trace(m => m("Calling: [.../classes/{0}...] From (referrer): [{1}]", YearQuarter, Request.UrlReferrer)); // TODO: come up with a better way to maintain various State flags ViewBag.Modality = Helpers.ConstructModalityList(f_oncampus, f_online, f_hybrid); ViewBag.Days = Helpers.ConstructDaysList(day_su, day_m, day_t, day_w, day_th, day_f, day_s); ViewBag.LinkParams = Helpers.getLinkParams(Request); ViewBag.timestart = timestart; ViewBag.timeend = timeend; ViewBag.latestart = latestart; ViewBag.avail = avail; IList<ISectionFacet> facets = Helpers.addFacets(timestart, timeend, day_su, day_m, day_t, day_w, day_th, day_f, day_s, f_oncampus, f_online, f_hybrid, avail, latestart, numcredits); YearQuarterModel model = new YearQuarterModel { ViewingSubjects = new List<SubjectModel>(), SubjectLetters = new List<char>(), }; try { using (OdsRepository repository = new OdsRepository(HttpContext)) { YearQuarter yrq = Helpers.DetermineRegistrationQuarter(YearQuarter, repository.CurrentRegistrationQuarter, RouteData); model.ViewingQuarter = yrq; model.NavigationQuarters = Helpers.GetYearQuarterListForMenus(repository); // set up all the ancillary data we'll need to display the View SetCommonViewBagVars(repository, avail, letter); // TODO: Refactor the following code to use ApiController.GetSubjectList() // after reconciling the noted differences between AllClasses() and YearQuarter() - 4/27/2012, [email protected] using (ClassScheduleDb db = new ClassScheduleDb()) { // Compile a list of active subjects char[] commonCourseChar = _apiSettings.RegexPatterns.CommonCourseChar.ToCharArray(); IList<string> activePrefixes = repository.GetCourseSubjects(yrq, facets).Select(p => p.Subject).ToList(); IList<Subject> subjects = new List<Subject>(); // NOTE: Unable to reduce the following loop to a LINQ statement because it complains about not being able to use TrimEnd(char[]) w/ LINQ-to-Entities // (Although it appears to be doing so just fine in the if statement below). - [email protected] foreach (Subject sub in db.Subjects) { // TODO: whether the CoursePrefix has active courses or not, any Prefix with a '&' will be included // because GetCourseSubjects() does not include the common course char. if (sub.CoursePrefixes.Select(sp => sp.CoursePrefixID).Any(sp => activePrefixes.Contains(sp.TrimEnd(commonCourseChar)))) { subjects.Add(sub); } } model.SubjectLetters = subjects.Select(s => s.Title.First()).Distinct().ToList(); model.ViewingSubjects = (letter != null ? subjects.Where(s => s.Title.StartsWith(letter, StringComparison.OrdinalIgnoreCase)).Distinct() : subjects ).Select(s => new SubjectModel { Title = s.Title, Slug = s.Slug, CoursePrefixes = s.CoursePrefixes.Select(p => p.CoursePrefixID).ToList() } ).ToList(); if (format == "json") { // NOTE: AllowGet exposes the potential for JSON Hijacking (see http://haacked.com/archive/2009/06/25/json-hijacking.aspx) // but is not an issue here because we are receiving and returning public (e.g. non-sensitive) data JsonResult json = Json(model, JsonRequestBehavior.AllowGet); return json; } return View(model); } } } catch (ArgumentOutOfRangeException ex) { if (ex.Message.ToUpper().Contains("MUST BE A VALID QUARTER TITLE")) { throw new HttpException(404, string.Format("'{0}' is not a recognized Quarter.", YearQuarter), ex); } _log.Error(m => m("An unhandled ArgumentOutOfRangeException ocurred, returning an empty Model to the YearQuarter view."), ex); } catch (Exception ex) { _log.Error(m => m("An unhandled exception occurred, returning an empty Model to the YearQuarter view."), ex); } // empty model return View(model); }
public void ForSubjectCommonCourse_CurrentRegistrationQuarter() { using (OdsRepository repository = new OdsRepository()) { string subject = "ENGL&"; YearQuarter yrq = repository.CurrentRegistrationQuarter; int sectionCount = repository.SectionCountForCourse(subject, yrq, TestHelper.GetFacets(false)); Assert.IsTrue(sectionCount > 0, string.Format("No sections found for '{0}' in '{1}'", subject, yrq.FriendlyName)); int expectedCount = _dataVerifier.GetSectionCount(string.Format("YearQuarterID = '{0}' AND CourseID LIKE '{1}%' AND CourseID LIKE '%&%'", yrq, subject)); Assert.AreEqual(expectedCount, sectionCount); } }
/// <summary> /// Gets the <see cref="YearQuarter"/> for the current, and future 2 quarters. /// </summary> public static IList<YearQuarter> GetFutureQuarters(OdsRepository repository) { IList<YearQuarter> futureQuarters = repository.GetFutureQuarters(3); return futureQuarters; }
// // GET: /Search/ public ActionResult Index(string searchterm, string Subject, string quarter, string timestart, string timeend, string day_su, string day_m, string day_t, string day_w, string day_th, string day_f, string day_s, string f_oncampus, string f_online, string f_hybrid, string avail, string latestart, string numcredits, int p_offset = 0) { // We don't currently support quoted phrases. - 4/19/2012, [email protected] searchterm = searchterm.Replace("\"", string.Empty); // TODO: This needs to be configurable if (quarter == "CE") { Response.Redirect("http://www.campusce.net/BC/Search/Search.aspx?q=" + searchterm, true); return null; } if (String.IsNullOrEmpty(searchterm.Trim())) { return RedirectToAction("AllClasses", "Classes", new { YearQuarterID = quarter }); } ViewBag.timestart = timestart; ViewBag.timeend = timeend; ViewBag.avail = avail; ViewBag.Modality = Helpers.ConstructModalityList(f_oncampus, f_online, f_hybrid); ViewBag.Days = Helpers.ConstructDaysList(day_su, day_m, day_t, day_w, day_th, day_f, day_s); ViewBag.Subject = Subject; ViewBag.searchterm = Regex.Replace(searchterm, @"\s+", " "); // replace each clump of whitespace w/ a single space (so the database can better handle it) ViewBag.ErrorMsg = string.Empty; IList<ISectionFacet> facets = Helpers.addFacets(timestart, timeend, day_su, day_m, day_t, day_w, day_th, day_f, day_s, f_oncampus, f_online, f_hybrid, avail, latestart, numcredits); ViewBag.LinkParams = Helpers.getLinkParams(Request, "submit"); using (OdsRepository repository = new OdsRepository()) { YearQuarter yrq = string.IsNullOrWhiteSpace(quarter) ? repository.CurrentYearQuarter : YearQuarter.FromFriendlyName(quarter); IList<YearQuarter> menuQuarters = Helpers.GetYearQuarterListForMenus(repository); QuarterNavigationModel quarterNavigation = new QuarterNavigationModel { NavigationQuarters = menuQuarters, CurrentQuarter = menuQuarters[0], ViewingQuarter = yrq, }; IList<Section> sections; using (_profiler.Step("API::GetSections()")) { if (string.IsNullOrWhiteSpace(Subject)) { sections = repository.GetSections(yrq, facets); } else { IList<string> prefixes = SubjectInfo.GetSubjectPrefixes(Subject); sections = repository.GetSections(prefixes, yrq, facets); } } int currentPage; int totalPages; int itemCount; IList<SectionWithSeats> sectionsEnum; IList<SearchResult> searchResults; SearchResultNoSectionModel noSectionSearchResults; IList<SectionsBlock> courseBlocks; using (ClassScheduleDb db = new ClassScheduleDb()) { searchResults = GetSearchResults(db, searchterm, quarter); noSectionSearchResults = GetNoSectionSearchResults(db, searchterm, yrq); sections = (from s in sections join r in searchResults on s.ID.ToString() equals r.ClassID select s).ToList(); sectionsEnum = Helpers.GetSectionsWithSeats(yrq.ID, sections, db); // do not count Linked sections (since we don't display them) itemCount = sectionsEnum.Count(s => !s.IsLinked); totalPages = (int)Math.Round((itemCount / ITEMS_PER_PAGE) + 0.5); currentPage = p_offset + 1; using (_profiler.Step("Getting just records for page")) { if (currentPage > totalPages && totalPages > 0) { currentPage = totalPages; } sectionsEnum = sectionsEnum.Skip(p_offset * ITEMS_PER_PAGE).Take(ITEMS_PER_PAGE).ToList(); } courseBlocks = Helpers.GroupSectionsIntoBlocks(sectionsEnum, db); } IEnumerable<string> allSubjects; using (_profiler.Step("Getting distinct list of subjects")) { allSubjects = sectionsEnum.Select(c => c.CourseSubject).Distinct().OrderBy(c => c); } SearchResultsModel model = new SearchResultsModel { ItemCount = itemCount, TotalPages = totalPages, CurrentPage = currentPage, Courses = courseBlocks, SearchResultNoSection = noSectionSearchResults, AllSubjects = allSubjects, QuarterNavigation = quarterNavigation, }; return View(model); } }
public ActionResult Index() { using (OdsRepository repository = new OdsRepository()) { ViewBag.CurrentYearQuarter = repository.CurrentYearQuarter; ViewBag.QuarterNavMenu = Helpers.GetYearQuarterListForMenus(repository); ViewBag.RegistrationQuarters = Helpers.GetFutureQuarters(repository); } return View(); }
/// <summary> /// /// </summary> /// <param name="facet"></param> /// <param name="includeQuarterFilter"></param> /// <returns></returns> public static IList<Section> GetSectionsWithFilter(ISectionFacet facet, bool includeQuarterFilter = true) { using (OdsRepository repository = new OdsRepository()) { IList<ISectionFacet> facets = GetFacets(facet, includeQuarterFilter); return repository.GetSections(facets); } }
public ActionResult ClassDetails(string Prefix, string ClassNum, string format) { ICourseID courseID = CourseID.FromString(Prefix, ClassNum); ClassDetailsModel model; using (OdsRepository repository = new OdsRepository(HttpContext)) { IList<Course> courses; using (_profiler.Step("ODSAPI::GetCourses()")) { courses = repository.GetCourses(courseID); } IList<YearQuarter> navigationQuarters = Helpers.GetYearQuarterListForMenus(repository); IList<YearQuarter> quartersOffered = new List<YearQuarter>(); string learningOutcomes = string.Empty; if (courses.Count > 0) { using (_profiler.Step("Getting Course counts (per YRQ)")) { // Identify which, if any, of the current range of quarters has Sections for this Course foreach (YearQuarter quarter in navigationQuarters) { // TODO: for better performance, overload method to accept more than one YRQ if (repository.SectionCountForCourse(courseID, quarter) > 0) { quartersOffered.Add(quarter); } } } // Get the course learning outcomes using (_profiler.Step("Retrieving course outcomes")) { learningOutcomes = Helpers.GetCourseOutcome(courseID); } } // Create the model model = new ClassDetailsModel { Courses = courses, CurrentQuarter = repository.CurrentYearQuarter, NavigationQuarters = navigationQuarters, QuartersOffered = quartersOffered, CMSFootnote = GetCmsFootnote(courseID), LearningOutcomes = learningOutcomes, }; Subject subject = SubjectInfo.GetSubjectFromPrefix(Prefix); if (subject != null) { SubjectInfoResult programInfo = SubjectInfo.GetSubjectInfo(subject.Slug); model.Slug = programInfo.Subject.Slug; model.SubjectTitle = programInfo.Subject.Title; model.SubjectIntro = programInfo.Subject.Intro; model.DepartmentTitle = programInfo.Department.Title; model.DepartmentURL = programInfo.Department.URL; model.DivisionTitle = programInfo.Division.Title; model.DivisionURL = programInfo.Division.URL; } } if (format == "json") { // NOTE: AllowGet exposes the potential for JSON Hijacking (see http://haacked.com/archive/2009/06/25/json-hijacking.aspx) // but is not an issue here because we are receiving and returning public (e.g. non-sensitive) data return Json(model, JsonRequestBehavior.AllowGet); } return View(model); }