示例#1
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var instructor          = _instructorRepository.GetById((int)id);
            var allCourses          = _courseRepository.GetAll();
            var coursesToInstructor = await _courseAssignmentRepository
                                      .CoursesToInstructorAsync(instructor.InstructorId);

            var model = new EditCreateViewModel()
            {
                Instructor         = instructor,
                AssignedCourseData = allCourses.Select(s => new AssignedCourseData()
                {
                    CourseId   = s.Id,
                    CourseName = s.CourseName,
                    Assigned   = coursesToInstructor.Exists(e => e.Course.Id == s.Id)
                }).ToList()
            };

            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> Edit(int id)
        {
            var instructor          = _instructorRepository.GetById(id);
            var allCourses          = _courseRepository.GetAll();
            var coursesToInstructor = await _courseAssignmentRepository.CoursesToInstructorAsync(instructor.InstructorId);

            var model = new CreateInstructorViewModel()
            {
                Instructor         = instructor,
                AssignedCourseData = allCourses.Select(s => new AssignedCourseData()
                {
                    CourseId   = s.CourseId,
                    CourseName = s.CourseName,
                    Assigned   = coursesToInstructor.Exists(x => x.Course.CourseId == s.CourseId)
                }).OrderBy(x => x.CourseName).ToList()
            };


            return(View(model));
        }