public ReportController() { ViewBag.Today = new DateTime(2018, 4, 16); _lectureDataService = new LectureDataService(); _lecturerDataService = new LecturerDataService(); _attendanceDataService = new AttendanceDataService(); _groupDataService = new GroupDataService(); }
private void UpdateAttendance(DateTime date, string cardNumber) { var currentTime = new DateTime(2018, 4, 16, 14, 27, 52); var studentDataService = new StudentDataService(); var student = studentDataService.GetByCardNumber(cardNumber); var groupDataService = new GroupDataService(); var group = groupDataService.GetByStudent(student.Id); var lectureDataService = new LectureDataService(); var lectures = lectureDataService.GetByGroupId(group.Id); var lectureId = -1; foreach (var lecture in lectures) { if (lecture.Occurences.FirstOrDefault(x => x.Date.ToShortDateString() == currentTime.ToShortDateString()) != null && lecture.LectureTime.LectureStart.AddMinutes(-5).TimeOfDay <= currentTime.TimeOfDay && lecture.LectureTime.LectureEnd.AddMinutes(5).TimeOfDay >= currentTime.TimeOfDay) { lectureId = lecture.Id; break; } } if (lectureId != -1) { var attendanceDataService = new AttendanceDataService(); var attendance = attendanceDataService.GetStudentAttendance(student.Id, lectureId); var dateString = currentTime.ToString("yyyy-MM-dd"); if (!attendance.AttendedLectures.Contains(dateString)) { attendance.AttendedLectures += dateString + ","; } attendanceDataService.UpdateLectures(attendance); } }