public ActionResult Index() { using (CoursesManager) { using (DeptManager) { using (InstManager) { using (PeopleManager) { var disp = new vmCourseSearch(); disp.Departments = DeptManager.GetAllDepartments().ToList(); var inst = InstManager.GetAllInstructors(); var people = PeopleManager.GetAllPeople(); var instr = from instructor in inst join person in people on instructor.PersonID equals person.ID select new KeyValuePair <int, string>(instructor.ID, string.Format("{0}, {1}", person.LastName, person.FirstMidName)); disp.Instructors = instr.ToDictionary(t => t.Key, t => t.Value); return(View(disp)); } } } } }
public ActionResult Index(vmCourseSearch vm) { List <CourseDetail> toreturn = new List <CourseDetail>(); IEnumerable <CourseDetail> courses = null; using (CoursesManager) { courses = CoursesManager.GetAllCourseDetails(); if (vm.SelectedDept > 0) { courses = courses.Where(c => c.DepartmentID == vm.SelectedDept); } if (vm.SelectedInst > 0) { courses = courses.Where(c => c.InstructorID == vm.SelectedInst); } if (!string.IsNullOrEmpty(vm.SearchText)) { courses = courses.Where(c => c.Title.Contains(vm.SearchText)); } JsonResult result = Json(courses.ToList()); return(result); } }