public ActionResult Details(int id) { #region Logic Here /* * Dispaly the course with drop downlist of its instructors */ #endregion var course = unit.CourseManager.GetById(id); // get the instructors who teach this course var instructorId = course.InstructorCourses.Where(a => a.Fk_CourseID == id). Select(a => a.Fk_InstructorId).ToList(); var instructors = ctx.Instructors.Where(a => instructorId.Contains(a.Id)); CourseInstructorVM courseVM = new CourseInstructorVM { CourseId = course.Id, CourseName = course.Name, CourseCode = course.Code, CourseHours = course.Hours, CourseHasInstructor = course.HasInstructor, Instructors = new SelectList(items: instructors, dataValueField: "Name", dataTextField: "Name", selectedValue: instructors) }; return(View(courseVM)); }
public ActionResult AssignCourseToInstructor(int id) { Course course = unit.CourseManager.GetById(id); List <Instructor> instructors = unit.InstructorManager.GetAllBind(); CourseInstructorVM courseVM = new CourseInstructorVM { CourseId = course.Id, CourseName = course.Name, Instructors = new SelectList(items: instructors, dataValueField: "Id", dataTextField: "Name", selectedValue: instructors) }; return(View(courseVM)); }
public ActionResult AssignCourseToInstructor(CourseInstructorVM courseInstructorVM) { // get entities var course = ctx.Courses.FirstOrDefault(c => c.Id == courseInstructorVM.CourseId); var instructor = ctx.Instructors.FirstOrDefault(c => c.Id == courseInstructorVM.InstructorId); var InstructorCourse = courseInstructorVM.InstructorCourse; // Make them equal to Zero because it always sent as "NULL" InstructorCourse.Fk_CourseID = 0; InstructorCourse.Fk_InstructorId = 0; course.HasInstructor = true; InstructorCourse.Fk_InstructorId = instructor.Id; InstructorCourse.Fk_CourseID = course.Id; ctx.InstructorCourses.Add(InstructorCourse); ctx.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Details(int id) { var instructor = unit.InstructorManager.GetById(id); // get the course who is teached this instructor var courseId = instructor.InstructorCourses.Where(a => a.Fk_InstructorId == id). Select(a => a.Fk_CourseID).ToList(); var courses = ctx.Courses.Where(a => courseId.Contains(a.Id)); CourseInstructorVM courseVM = new CourseInstructorVM { InstructorId = instructor.Id, InstructorName = instructor.Name, InstructorDept = instructor.Department, InstructorMail = instructor.Mail, InstructorPhone = instructor.Phone, Courses = new SelectList(items: courses, dataValueField: "Name", dataTextField: "Name", selectedValue: courses) }; return(View(courseVM)); }