public ViewResult EducationStudentsDays(int educationId, int semesterNo, TimeSpan span) { Education education = educationRepo.Educations.FirstOrDefault(e => e.EducationId == educationId); List <Student> studentList = studentRepo.GetAllStudentsFromEducationSemester(education, semesterNo); List <string> students = new List <string>(); List <string> dates = GetDateSpan(span); Dictionary <string, Dictionary <string, string> > dic = new Dictionary <string, Dictionary <string, string> >(); foreach (Student student in studentList) { Dictionary <string, string> dico = new Dictionary <string, string>(); foreach (string date in dates) { Absence a = absenceRepo.AbsenceForDateEducationStudent(education, DateTime.Parse(date), student); dico.Add(date, a != null ? a.Status : ""); } string s = ShortenName(student.Name); students.Add(s); dic.Add(s, dico); } return(View("CourseStudentsDays", new StudentsDaysViewModel { Dates = dates, StudentList = students, StudentStatuses = dic, Education = education, Course = new Course(), SemesterNo = semesterNo })); }
private DateTime FindTimeSpan(TimeSpan timeSpan, DateTime todaysDate) { DateTime checkDate = new DateTime(); switch (timeSpan) { case TimeSpan.Week: checkDate = todaysDate.AddDays(-7); break; case TimeSpan.TwoWeeks: checkDate = todaysDate.AddDays(-14); break; case TimeSpan.ThreeWeeks: checkDate = todaysDate.AddDays(-21); break; case TimeSpan.Month: checkDate = todaysDate.AddMonths(-1); break; default: break; } return(checkDate); }
public ViewResult CourseStudentsDays(int courseId, TimeSpan span) { if (courseId == 0) { courseId = 1; } Course course = courseRepo.Courses.FirstOrDefault(c => c.CourseId == courseId); List <Student> studentList = studentRepo.GetAllStudentsFromCourses(course); List <string> students = new List <string>(); List <string> dates = GetDateSpan(span); Dictionary <string, Dictionary <string, string> > dic = new Dictionary <string, Dictionary <string, string> >(); foreach (Student student in studentList) { Dictionary <string, string> dico = new Dictionary <string, string>(); foreach (string date in dates) { Absence a = absenceRepo.AbsenceForDateCourseStudent(course, DateTime.Parse(date), student); dico.Add(date, a != null ? a.Status : ""); } string s = ShortenName(student.Name); students.Add(s); dic.Add(s, dico); } return(View("CourseStudentsDays", new StudentsDaysViewModel { Dates = dates, StudentList = students, StudentStatuses = dic, Course = course, Education = new Education() })); }
private List <string> GetDateSpan(TimeSpan span) { List <string> dates = new List <string>(); switch (span) { case TimeSpan.Week: for (DateTime i = DateTime.Today.AddDays(-6); i <= DateTime.Today; i = i.AddDays(1)) { dates.Add(i.ToShortDateString()); } break; case TimeSpan.TwoWeeks: for (DateTime i = DateTime.Today.AddDays(-13); i <= DateTime.Today; i = i.AddDays(1)) { dates.Add(i.ToShortDateString()); } break; case TimeSpan.ThreeWeeks: for (DateTime i = DateTime.Today.AddDays(-20); i <= DateTime.Today; i = i.AddDays(1)) { dates.Add(i.ToShortDateString()); } break; case TimeSpan.Month: for (DateTime i = DateTime.Today.AddMonths(-1).AddDays(1); i <= DateTime.Today; i = i.AddDays(1)) { dates.Add(i.ToShortDateString()); } break; } return(dates); }