コード例 #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);
        }
        // GET: School/Instructor
        public ActionResult Index()
        {
            List <InstructorViewModel> listInstructor = new List <InstructorViewModel>();
            var result = _instuctorRepository.GetAllInstructors();

            foreach (var x in result)
            {
                InstructorViewModel instructorVM = new InstructorViewModel();
                instructorVM.Id                = x.Id;
                instructorVM.InstructorName    = x.InstructorName;
                instructorVM.InstructorContact = x.InstructorContact;
                listInstructor.Add(instructorVM);
            }
            return(View(listInstructor));
        }
コード例 #3
0
 public async Task <IActionResult> Get()
 {
     return(new ObjectResult(await _instructorRepository.GetAllInstructors()));
 }