private void UpdateInstructorCourses(string[] selectedCourses, IEnumerable <Course> courses) { if (selectedCourses == null) { CourseInstructors = new List <CourseInstructor>(); return; } var selectedCoursesHS = new HashSet <string>(selectedCourses); var instructorCourses = new HashSet <int> (CourseInstructors.Select(c => c.CourseID)); foreach (var course in courses) { if (selectedCoursesHS.Contains(course.Id.ToString())) { if (!instructorCourses.Contains(course.Id)) { CourseInstructors.Add(new CourseInstructor { Course = course, Instructor = this }); } } else { if (instructorCourses.Contains(course.Id)) { var toRemove = this.CourseInstructors.Single(ci => ci.CourseID == course.Id); CourseInstructors.Remove(toRemove); } } } }
private static CourseInstructors InstructorsMapCourse(IDataReader reader) { CourseInstructors item = new CourseInstructors(); int startingIndex = 0; item.CourseId = reader.GetSafeInt32(startingIndex++); item.InstructorId = reader.GetSafeInt32(startingIndex++); item.Name = reader.GetSafeString(startingIndex++); return(item); }
public Course Get(int id) { Course course = null; DataProvider.ExecuteCmd(GetConnection, "dbo.Courses_SelectByIdV2", inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Id", id); }, map : delegate(IDataReader reader, short set) { if (set == 0) { course = MapCourse(reader); } else if (set == 1) { CourseTag ct = TagMapCourse(reader); if (course.Tags == null) { course.Tags = new List <CourseTag>(); } course.Tags.Add(ct); } else if (set == 2) { CourseInstructors imc = InstructorsMapCourse(reader); if (course.Instructors == null) { course.Instructors = new List <CourseInstructors>(); } course.Instructors.Add(imc); } else if (set == 3) { BaseCourse bc = PrereqsMapCourse(reader); if (course.Prereqs == null) { course.Prereqs = new List <BaseCourse>(); } course.Prereqs.Add(bc); } }); return(course); }
private static CourseInstructors InstructorsMapCourse(IDataReader reader) { CourseInstructors item = new CourseInstructors(); int startingIndex = 0; item.CourseId = reader.GetSafeInt32(startingIndex++); item.InstructorId = reader.GetSafeInt32(startingIndex++); item.Name = reader.GetSafeString(startingIndex++); return item; }