public void Models_SchoolCalendarViewModel_Default_Instantiate_Should_Pass() { // Act var result = new SchoolCalendarViewModel(); // Assert Assert.IsNotNull(result, TestContext.TestName); }
/// <summary> /// Calendar Index /// </summary> /// <returns></returns> // GET: Calendar public ActionResult Index() { var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext); if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser)) { return(RedirectToAction("Login", "Admin")); } var mySchoolDaysData = Backend.DataSourceBackend.Instance.SchoolCalendarBackend.Index(); // Removed null check: the data is OK to be count=0 but not possible to be null //if (mySchoolDaysData == null) //{ // // Send to Error Page // return RedirectToAction("Error", "Home"); //} var myData = new SchoolCalendarViewModel { SchoolDays = mySchoolDaysData, CurrentDate = UTCConversionsBackend.UtcToKioskTime(DateTimeHelper.Instance.GetDateTimeNowUTC()) }; myData.FirstDay = SchoolDismissalSettingsBackend.Instance.GetDefault().DayFirst; myData.LastDay = SchoolDismissalSettingsBackend.Instance.GetDefault().DayLast; //Get the First and last month, and set the dates to the first of those months. var dateStart = DateTime.Parse(myData.FirstDay.Month.ToString() + "/01/" + myData.FirstDay.Year.ToString()); // Go to the month after the last date var dateEnd = DateTime.Parse((myData.LastDay.Month + 1).ToString() + "/01/" + myData.LastDay.Year.ToString()); dateEnd.AddDays(-1); // Back up 1 day to be the last day of the month DateTime currentDate = new DateTime(); currentDate = dateStart; // For every day from the start of the school year, until the end of the school year or now... while (currentDate.CompareTo(dateEnd) < 0) { if (currentDate.Day == 1) { // For each month, build a list of the days for that month var temp = myData.SchoolDays.Where(m => m.Date.Month == currentDate.Month).ToList(); myData.Months.Add(temp); } currentDate = currentDate.AddDays(1); } return(View(myData)); }
/// <summary> /// Calendar Index /// </summary> /// <returns></returns> // GET: Calendar public ActionResult Index() { var mySchoolDaysData = Backend.DataSourceBackend.Instance.SchoolCalendarBackend.Index(); if (mySchoolDaysData == null) { // Send to Error Page return(RedirectToAction("Error", "Home")); } var myData = new SchoolCalendarViewModel { SchoolDays = mySchoolDaysData, CurrentDate = DateTime.UtcNow, }; myData.FirstDay = myData.SchoolDays.First().Date; myData.LastDay = myData.SchoolDays.Last().Date; //Get the First and last month, and set the dates to the first of those months. var dateStart = DateTime.Parse(myData.SchoolDays.First().Date.Month.ToString() + "/01/" + myData.SchoolDays.First().Date.Year.ToString()); // Go to the month after the last date var dateEnd = DateTime.Parse((myData.SchoolDays.Last().Date.Month + 1).ToString() + "/01/" + myData.SchoolDays.Last().Date.Year.ToString()); dateEnd.AddDays(-1); // Back up 1 day to be the last day of the month DateTime currentDate = new DateTime(); currentDate = dateStart; // For every day from the start of the school year, until the end of the school year or now... while (currentDate.CompareTo(dateEnd) < 0) { if (currentDate.Day == 1) { // For each month, build a list of the days for that month var temp = myData.SchoolDays.Where(m => m.Date.Month == currentDate.Month).ToList(); myData.Months.Add(temp); } currentDate = currentDate.AddDays(1); } return(View(myData)); }