public ActionResult Index(int? beginMonth, int? beginDay, int? beginYear, int? endMonth, int? endDay, int? endYear, string stationState, string stationName) { // preserve form entries ViewBag.BeginMonth = beginMonth; ViewBag.BeginDay = beginDay; ViewBag.BeginYear = beginYear; ViewBag.EndMonth = endMonth; ViewBag.EndDay = endDay; ViewBag.EndYear = endYear; ViewBag.StationState = stationState; ViewBag.StationName = stationName; // validation logic - combination of begin month and day must be greater than or equal to the end month and day // validation logic - end year must be greater than or equal to the begin year // cannot us data datatype validation as this won't work with the day-range logic of the datasets // end validation errors to the view if (endYear < beginYear) { ModelState.AddModelError("Years", "ERROR - The end year must be greater than or equal to begin year"); } else if (endMonth < beginMonth) { ModelState.AddModelError("Months", "ERROR - The end month must be greater than or equal to the begin month."); } else if ((endMonth == beginMonth) && (endDay < beginDay)) { ModelState.AddModelError("Days", "ERROR - The end day must be greater than or equal to the begin day."); } // choose view based on model validation if (ModelState.IsValid) { // build request objects and table view ISummaryRequest summaryRequest = new SummaryRequest(stationName, beginMonth, beginDay, beginYear, endMonth, endDay, endYear); ITablesView tableView = new TablesView(summaryRequest); return View("SummaryTables", tableView); } else { // build request objects and table view // null all values sent to SummaryRequest to avoid data errors ISummaryRequest summaryRequest = new SummaryRequest(null, null, null, null, null, null, null); ITablesView tableView = new TablesView(summaryRequest); return View("SummaryTables", tableView); } }
public void BuildSummaryRequestObject() { // this test attempts to build a summary request object // and verify the data properties returned // arrange - build a summary request object with values SummaryRequest sr = new SummaryRequest("13904", 7, 5, 2013, 7, 10, 2013); // act // assert - check returned values valid Assert.IsNotNull(sr); Assert.AreEqual(sr.StationName, "13904"); Assert.AreEqual(sr.DateDict["beginMonth"], (int)7); Assert.AreEqual(sr.DateDict["beginDay"], (int)5); Assert.AreEqual(sr.DateDict["beginYear"], (int)2013); Assert.AreEqual(sr.DateDict["endMonth"], (int)7); Assert.AreEqual(sr.DateDict["endDay"], (int)10); Assert.AreEqual(sr.DateDict["endYear"], (int)2013); // arrange - build a summary request object with nulls SummaryRequest srNull = new SummaryRequest(null, null, null, null, null, null, null); // act // assert - check returned values valid // object itself should exist, but all properties are null Assert.IsNotNull(srNull); Assert.AreEqual(srNull.StationName, null); Assert.AreEqual(srNull.DateDict["beginMonth"], null); Assert.AreEqual(srNull.DateDict["beginDay"], null); Assert.AreEqual(srNull.DateDict["beginYear"], null); Assert.AreEqual(srNull.DateDict["endMonth"], null); Assert.AreEqual(srNull.DateDict["endDay"], null); Assert.AreEqual(srNull.DateDict["endYear"], null); }