public ActionResult Search(int?year, int?month, int?day, string url_title) { //if year exists if (year.HasValue) { //is year valid if (year.Value > DateTime.Now.Year) { throw new Exception("KSULAX||the year " + year.Value + " is in the future."); } //if month exists if (month.HasValue) { //is month valid if (month.Value >= 1 && month.Value <= 12) { if (year.Value.Equals(DateTime.Now.Year) && month.Value > DateTime.Now.Month) { throw new Exception("KSULAX||" + new DateTime(year.Value, month.Value, 1).ToString("MMMM yyyy") + " is in the future."); } //if day exists if (day.HasValue) { //is day valid if (day.Value >= 1 && day.Value <= DateTime.DaysInMonth(year.Value, month.Value)) { //if day is in the future if (year.Value.Equals(DateTime.Now.Year) && month.Value.Equals(DateTime.Now.Month) && day.Value > DateTime.Now.Day) { throw new Exception("KSULAX||" + new DateTime(year.Value, month.Value, day.Value).ToString("dd MMMM yyyy") + " is in the future."); } //if url_title is empty if (string.IsNullOrEmpty(url_title)) { var stories = new StoryBriefListModel(_newsBL.NewsYearMonthDay(new DateTime(year.Value, month.Value, day.Value)), this.Request.Url.ToString()); if (stories.Stories.Count > 0) { return(View("Search", stories)); } else { throw new Exception("KSULAX||we don't have any stories for " + new DateTime(year.Value, month.Value, day.Value).ToString("dd MMMM yyyy") + "."); } } return(Story(year.Value, month.Value, day.Value, url_title)); } else { throw new Exception("KSULAX||" + year.GetValueOrDefault() + "/" + month.GetValueOrDefault() + "/" + day.GetValueOrDefault() + " is not a valid date."); } } else { var stories = new StoryBriefListModel(_newsBL.NewsYearMonth(new DateTime(year.Value, month.Value, 1)), this.Request.Url.ToString()); if (stories.Stories.Count > 0) { return(View("Search", stories)); } else { throw new Exception("KSULAX||we don't have any stories for " + new DateTime(year.Value, month.Value, 1).ToString("MMMM yyyy") + "."); } } } else { throw new Exception("KSULAX||" + year.GetValueOrDefault() + "/" + month.GetValueOrDefault() + "/" + day.GetValueOrDefault() + " is not a valid date."); } } else { var stories = new StoryBriefListModel(_newsBL.NewsYear(new DateTime(year.Value, 1, 1)), this.Request.Url.ToString()); if (stories.Stories.Count > 0) { return(View("Search", stories)); } else { throw new Exception("KSULAX||we don't have any stories for the year " + year.Value + "."); } } } else { throw new Exception("KSULAX||" + year.GetValueOrDefault() + "/" + month.GetValueOrDefault() + "/" + day.GetValueOrDefault() + " is not a valid date."); } }