CTCClassSchedule.Controllers.ClassesController.YearQuarter C# (CSharp) Метод

YearQuarter() приватный Метод

private 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 ) : System.Web.Mvc.ActionResult
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 string
Результат System.Web.Mvc.ActionResult
        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);
        }