public IActionResult Attendance(decimal?gr, decimal?subj) { var timetable = db.Timetable.Where(t => t.TeacherAccountId == CurrentUser.AccountId); var records = db.Records.Where(r => timetable.FirstOrDefault(t => t.RecordId == r.RecordId) != null); var subjects = db.Subjects.Where(s => records.FirstOrDefault(r => r.SubjectId == s.SubjectId) != null); var students = db.Students.Where(s => records.FirstOrDefault(r => r.StudentAccountId == s.AccountId) != null); var groups = students .Select(s => s.StudentGroup) .Distinct() .OrderBy(s => s); TeacherAttendanceViewModel model = new TeacherAttendanceViewModel { Subjects = subjects, Groups = groups, Records = null, Students = null, CurrentSubject = null }; if (gr != null && subj != null) { var newRecords = records.Where(r => r.SubjectId == subj && students.FirstOrDefault(s => s.AccountId == r.StudentAccountId).StudentGroup == gr); var newStudents = students.Where(s => newRecords.FirstOrDefault(r => r.StudentAccountId == s.AccountId) != null); var subject = db.Subjects.FirstOrDefault(s => s.SubjectId == subj); model.Records = newRecords; model.Students = newStudents; model.CurrentSubject = subject; } return(View("Attendance", model)); }
public IActionResult Attendance(TeacherAttendanceViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Attendance")); } return(RedirectToAction("Attendance", new Dictionary <string, object> { { "gr", model.CurrentGroupId }, { "subj", model.CurrentSubjectId } })); }