Exemple #1
0
        // GET: School/InstructorCourses
        public ActionResult Index()
        {
            List <InstructorCourseViewModel> lst = (from ic in _instructorCourseRepository.GetAllInstructorCourses()
                                                    join i in _instructorRepository.GetAllInstructors()
                                                    on ic.InstructorId equals i.Id
                                                    join c in _courseRepository.GetAllCourses()
                                                    on ic.CourseId equals c.Id

                                                    select new InstructorCourseViewModel
            {
                Id = ic.Id,
                InstructorName = i.InstructorName,
                CourseName = c.CourseName
            }).ToList();

            return(View(lst));
            //List<InstructorCourseViewModel> lst = new List<InstructorCourseViewModel>();
            //var result = db.tblInstructorCourses.Include(t => t.tblCourse).Include(t => t.tblInstructor);

            //foreach (var x in result)
            //{
            //    InstructorCourseViewModel icVM = new InstructorCourseViewModel();
            //    icVM.Id = x.Id;
            //    icVM.CourseId = x.Id;
            //    icVM.InstructorId = x.InstructorId;
            //    lst.Add(icVM);

            //}

            //return View(lst);
        }