示例#1
0
        public ActionResult TeacherStudentsAndGrades(int?teacherId)
        {
            if (teacherId == 0 || !teacherId.HasValue)
            {
                return(RedirectToAction("Index"));
            }

            teacherService = new TeacherService();
            studentService = new StudentService();

            Teacher teacher = teacherService.getCorrespondingTeacher((int)teacherId);

            if (teacher == null)
            {
                return(RedirectToAction("Index"));
            }

            IEnumerable <StudentSubject> teacherStudentSubjects = teacherService
                                                                  .GetTeacherStudentSubjectsByTeacherId((int)teacherId);

            if (teacherStudentSubjects.Count() == 0)
            {
                return(RedirectToAction("Index"));
            }

            IEnumerable <Student> teachersStudents = studentService
                                                     .GetStudentsByStudentSubjects(teacherStudentSubjects.ToList());

            if (teachersStudents.Count() == 0)
            {
                return(RedirectToAction("Index"));
            }

            IEnumerable <Subject> teachersSubjects = teacherService
                                                     .GetTeachersSubjectsFromTeachersStudentSubjectList(teacherStudentSubjects);

            if (teachersSubjects.Count() == 0)
            {
                return(RedirectToAction("Index"));
            }

            List <TeacherStudentsAndGradesViewModel> viewModel = teacherService
                                                                 .CreateTeacherStudentsAndGradesViewModel(teacher, teacherStudentSubjects, teachersStudents,
                                                                                                          teachersSubjects);

            return(View(viewModel));
        }