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);
}
}