/// <summary> /// Allow choosing only the courses that the selected teacher can teach /// </summary> private void ShowSelectedTeacherCourses() { // Reset the teacher's available courses collection TeacherAvailableCourses.Clear(); if (SelectedTeacher != NOT_ASSIGNED) { // Get the selected teacher's information Teacher selectedTeacher = _schoolData.Teachers.Find(SelectedTeacher); bool isHomeroomTeacherClass = selectedTeacher.classID == SelectedClass; // Update the teacher courses collection with this teaher's courses TeacherAvailableCourses = new ObservableDictionary <int, string>(TeacherCoursesHandler.GetTeacherCoursesNames(selectedTeacher, isHomeroomTeacherClass)); } // Update the selected course per the new courses collection if (TeacherAvailableCourses.Count() > 0) { SelectedCourse = TeacherAvailableCourses.First().Key; } else { SelectedCourse = NOT_ASSIGNED; } // For some reason, after re-initializing a collection, a related selection in it is not updated properly in the view unless called explicitly OnPropertyChanged("SelectedCourse"); }
/// <summary> /// Get the names of all the courses a teacher teaches /// </summary> /// <param name="teacher">The teacher</param> /// <returns>String with the names of all the teacher's courses</returns> private string GetTeacherCourseNames(Teacher teacher) { string courseNames = string.Empty; // Get the name of each course the teacher teaches foreach (string teacherCourseName in TeacherCoursesHandler.GetTeacherCoursesNames(teacher, false).Values) { courseNames += teacherCourseName + ", "; } // Remove the last ', ' courseNames = courseNames.Substring(0, courseNames.Length - 2); return(courseNames); }
/// <summary> /// Gather all the courses a specific teacher teaches /// </summary> /// <param name="teacher">The teacher to use</param> private void GatherTeacherCourses(Teacher teacher) { // Reset the Courses collection to fit the current teacher Courses = new ObservableDictionary <int, string>(TeacherCoursesHandler.GetTeacherCoursesNames(teacher, true)); // Automatically select a course if possible if (Courses.Count() > 0) { SelectedCourse = Courses.First().Key; } else { SelectedCourse = NOT_ASSIGNED; } // For some reason the selections are not updated properly in the view unless called again OnPropertyChanged("SelectedCourse"); }