예제 #1
0
        public ActionResult Index(int?id, int?courseID)
        {
            var viewModel = new TeacherIndexData
            {
                Teachers = db.Teachers
                           .Include(i => i.OfficeAssignment)
                           .Include(i => i.Courses.Select(c => c.Department))
                           .OrderBy(i => i.LastName)
            };

            if (id != null)
            {
                ViewBag.TeacherID = id.Value;
                viewModel.Courses = viewModel.Teachers
                                    .Where(i => i.ID == id.Value).Single().Courses;
            }

            if (courseID != null)
            {
                ViewBag.CourseID = courseID.Value;
                viewModel.Classs = viewModel.Courses
                                   .Where(c => c.CourseID == courseID).Single().Classs;
            }

            return(View(viewModel));
        }
예제 #2
0
        // GET: Teachers
        public async Task <IActionResult> Index(int?id, int?subjectID)
        {
            var viewModel = new TeacherIndexData
            {
                Teachers = await _context.Teachers.GetAll()
                           .Include(i => i.PositionAssignments)
                           .Include(i => i.SubjectAssignments)
                           .ThenInclude(i => i.Subject)
                           .ThenInclude(i => i.SchoolClass)
                           .OrderBy(i => i.LastName)
                           .ToListAsync()
            };

            if (id != null)
            {
                ViewData["TeacherID"] = id.Value;
                var teacher = viewModel.Teachers.Single(i => i.ID == id.Value);
                viewModel.Subjects = teacher.SubjectAssignments.Select(s => s.Subject);
            }

            if (subjectID != null)
            {
                ViewData["SubjectID"] = subjectID.Value;
                var selectedSubject = viewModel.Subjects.Single(x => x.SubjectID == subjectID);
                _context.Subjects.Update(selectedSubject);
                viewModel.Enrollments = selectedSubject.Enrollments;
            }

            return(View(viewModel));
        }
예제 #3
0
        // GET: Teacher
        public ActionResult Index(int?id, int?CourseID)
        {
            var viewModel = new TeacherIndexData();

            viewModel.Instructors = db.Teachers
                                    .Include(i => i.OfficeAssignment)
                                    .Include(i => i.Courses.Select(c => c.Department))
                                    .OrderBy(i => i.FirstName);

            if (id != null)
            {
                ViewBag.TeacherID = id.Value;
                viewModel.Courses = viewModel.Instructors.Where(
                    i => i.Id == id.Value).Single().Courses;
            }

            if (CourseID != null)
            {
                ViewBag.CourseID = CourseID.Value;
                // viewModel.Enrollments = viewModel.Courses.Where(
                //    x => x.CourseID == CourseID).Single().Enrollments;

                var selectedCourse = viewModel.Courses.Where(x => x.CourseID == CourseID).Single();
                db.Entry(selectedCourse).Collection(x => x.Enrollments).Load();
                foreach (Enrollment enrollment in selectedCourse.Enrollments)
                {
                    db.Entry(enrollment).Reference(x => x.Student).Load();
                }

                viewModel.Enrollments = selectedCourse.Enrollments;
            }

            return(View(viewModel));
        }
예제 #4
0
        // GET: Teacher
        public ActionResult Index(int?id, int?trackID)
        {
            var viewModel = new TeacherIndexData();

            viewModel.Teachers = db.Teachers
                                 .Include(i => i.LocationAssignment)
                                 .Include(i => i.Tracks.Select(c => c.Company))
                                 .OrderBy(i => i.LastName);

            if (id != null)
            {
                ViewBag.TeacherID = id.Value;
                viewModel.Tracks  = viewModel.Teachers.Where(
                    i => i.ID == id.Value).Single().Tracks;
            }

            if (trackID != null)
            {
                ViewBag.TrackID = trackID.Value;
                // Lazy loading
                //viewModel.Enrollments = viewModel.Courses.Where(
                //    x => x.CourseID == courseID).Single().Enrollments;
                // Explicit loading
                var selectedTrack = viewModel.Tracks.Where(x => x.TrackID == trackID).Single();
                db.Entry(selectedTrack).Collection(x => x.Enrollments).Load();
                foreach (Enrollment enrollment in selectedTrack.Enrollments)
                {
                    db.Entry(enrollment).Reference(x => x.Car).Load();
                }

                viewModel.Enrollments = selectedTrack.Enrollments;
            }

            return(View(viewModel));
        }
예제 #5
0
        // GET: Teacher
        public ActionResult Index(int?id, int?courseID)
        {
            //the eager loading
            var viewModel = new TeacherIndexData();

            viewModel.Teachers = db.Teachers
                                 .Include(i => i.OfficeAssignment)
                                 .Include(i => i.Courses.Select(c => c.Department))
                                 .OrderBy(i => i.LastName);

            if (id != null)
            {
                ViewBag.InstructorID = id.Value;
                viewModel.Courses    = viewModel.Teachers.Where(
                    i => i.ID == id.Value).Single().Courses;
            }

            if (courseID != null)
            {
                ViewBag.CourseID      = courseID.Value;
                viewModel.Enrollments = viewModel.Courses.Where(
                    x => x.CourseID == courseID).Single().Enrollments;
            }
            return(View(viewModel));
        }
예제 #6
0
        // GET: Teachers
        public async Task <IActionResult> Index(int?id, int?courseId)
        {
            var data = new TeacherIndexData();

            data.TeachersList = await _context.Teachers.Include(a => a.Office)
                                .Include(a => a.TeacherCourses).ThenInclude(m => m.Course)
                                .ThenInclude(m => m.Enrollments).ThenInclude(m => m.Student)
                                .ThenInclude(p => p.Enrollments).ThenInclude(p => p.Course)
                                .ThenInclude(p => p.Department).AsNoTracking().ToListAsync();

            if (id != null)
            {
                ViewData["TeacherId"] = id.Value;
                var teacher = data.TeachersList.Single(m => m.Id == id.Value);
                data.CourseList = teacher.TeacherCourses.Select(a => a.Course).ToList();
            }

            if (courseId != null)
            {
                ViewData["CourseId"] = courseId.Value;
                data.EnrollmentList  = data.CourseList.Single(m => m.Id == courseId.Value).Enrollments.ToList();
            }

            return(View(data));
        }
예제 #7
0
        // GET: Teacher
        public ActionResult Index(int?id)
        {
            var viewModel = new TeacherIndexData
            {
                Teachers = db.Teachers
                           .OrderBy(i => i.Name),
                Subjects = db.Subjects
                           .Include(i => i.Course)
            };



            if (id != null)
            {
                ViewBag.SubjectID     = id.Value;
                viewModel.Enrollments = viewModel.Subjects.Single(
                    x => x.TeacherID == id).Enrollments;
            }

            return(View(viewModel));
        }