示例#1
0
        public async Task <IActionResult> Index(int?id, int?courseId)
        {
            var allInstructors = await _instructorRepository.InstructorsAsync();

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

            if (id != null)
            {
                ViewData["InstructorId"] = id.Value;
                var instructor = model.Instructors.FirstOrDefault(x => x.InstructorId == id);
                if (instructor != null)
                {
                    model.Courses = instructor.CourseAssignments.Select(s => s.Course); //LinqPad kullanıldı.
                }
            }

            if (courseId != null)
            {
                ViewData["CourseId"] = courseId.Value;
                model.Enrollments    = model.Courses.FirstOrDefault(x => x.Id == courseId)?.Enrollments;
            }

            return(View(model));
        }