Beispiel #1
0
        public async Task <IActionResult> Index(int?id, int?CourseId)
        {
            var allInstructors = await _instructorRepository.Instructors();

            var model = new InstructorViewModel()
            {
                Instructors = allInstructors
            };

            if (id != null)
            {
                var instructor = model.Instructors.FirstOrDefault(x => x.InstructorId == id);

                model.Courses = instructor.CourseAssignments.Select(s => s.Course);

                if (instructor != null)
                {
                    model.Courses = instructor.CourseAssignments.Select(s => s.Course);
                }
            }

            if (CourseId != null)
            {
                ViewData["CourseId"] = CourseId.Value;

                model.Enrollments = model.Courses.FirstOrDefault(x => x.CourseId == CourseId).Enrollments;
            }

            return(View(model));
        }