public void Initialize(Person connectedPerson) { ConnectedPerson = connectedPerson; // Get the list of existing classes ClassesTableData = new ObservableCollection <ClassData>(_schoolData.Classes.AsEnumerable().Select(currClass => ModelClassToClassData(currClass)).ToList()); // Create the basic list of available classes AvailableTeachers.Clear(); // Add a 'No teacher' option, as not all classes have a teacher assigned to them. AvailableTeachers.Add(NOT_ASSIGNED, "אין מורה משויך"); // Create the list of teachers that are not homeroom teachers already. _schoolData.Teachers.Where(teacher => teacher.classID == null && !teacher.Person.User.isDisabled).ToList() .ForEach(teacher => AvailableTeachers.Add(teacher.teacherID, teacher.Person.firstName + " " + teacher.Person.lastName)); // Create the basic list of available rooms AvailableRooms.Clear(); // Add a 'no room' option, as not all classes have an an assigned room. AvailableRooms.Add(NOT_ASSIGNED, "אין חדר משויך"); // Create the list of rooms that are not assigned to a specific class already _schoolData.Rooms.Where(room => room.Classes.Count() == 0).ToList() .ForEach(room => AvailableRooms.Add(room.roomID, room.roomName)); // Reset selections SelectedTeacher = NOT_ASSIGNED; SelectedRoom = NOT_ASSIGNED; // For some reason, after re-initializing this view, the selections are not updated properly in the view unless called again OnPropertyChanged("SelectedTeacher"); OnPropertyChanged("SelectedRoom"); }
/// <summary> /// Choose a specific class and view its information. /// </summary> /// <param name="selectedClass">The class's data</param> private void UseSelectedClass(ClassData selectedClass) { // Cleanup previous selections SelectedTeacher = NOT_ASSIGNED; SelectedRoom = NOT_ASSIGNED; ClassName = string.Empty; LessonsInSelectedClass = new ObservableCollection <LessonInClass>(); StudentsInSelectedClass = new ObservableCollection <string>(); // Remove the previous class's homeroom teacher from the available teachers list as he/she are already assigned to the previous class if (_previousHomeroomTeacher != null) { AvailableTeachers.Remove(_previousHomeroomTeacher.Value); } // Remove the previous class's room from the available rooms list as it is already assigned to the previous class if (_previousRoom != null) { AvailableRooms.Remove(_previousRoom.Value); } // Update the properties per the selected class if (selectedClass != null) { ClassName = selectedClass.Name; // If the class has an teacher, add it first to the available teachers list if (selectedClass.HomeroomTeacherID != null) { AvailableTeachers.Add(selectedClass.HomeroomTeacherID.Value, selectedClass.HomeroomTeacherName); SelectedTeacher = selectedClass.HomeroomTeacherID.Value; } // If the class has a room associated with it, add it first to the available rooms list if (selectedClass.RoomID != null) { AvailableRooms.Add(selectedClass.RoomID.Value, selectedClass.RoomName); SelectedRoom = selectedClass.RoomID.Value; } // Save the homeroom teacher and room IDs so they can be removed when we select another class _previousHomeroomTeacher = selectedClass.HomeroomTeacherID; _previousRoom = selectedClass.RoomID; // Create the list of lessons in the current class if (selectedClass.LessonsInThisClass != null) { LessonsInSelectedClass = new ObservableCollection <LessonInClass>(selectedClass.LessonsInThisClass); } // Create the list of students in the current clas if (selectedClass.StudentsInThisClass != null) { StudentsInSelectedClass = new ObservableCollection <string>(selectedClass.StudentsInThisClass); } } }
public void Initialize(Person connectedPerson) { ConnectedPerson = connectedPerson; ResetData(); // Create the lists of possible classes, courses, teachers _schoolData.Classes.ToList().ForEach(schoolClass => AvailableClasses.Add(schoolClass.classID, schoolClass.className)); _schoolData.Courses.ToList().ForEach(course => AvailableCourses.Add(course.courseID, course.courseName)); _schoolData.Teachers.Where(teacher => !teacher.Person.User.isDisabled).ToList() .ForEach(teacher => AvailableTeachers.Add(teacher.teacherID, teacher.Person.firstName + " " + teacher.Person.lastName)); // Initialize the rooms list. Note that a room is optional and therefore has a NOT_ASSIGNED option AvailableRooms.Add(NOT_ASSIGNED, "ללא"); _schoolData.Rooms.ToList().ForEach(room => AvailableRooms.Add(room.roomID, room.roomName)); SearchingByClass = true; // For some reason, after re-initializing this view, the selections are not updated properly in the view unless called again OnPropertyChanged("SelectedClass"); OnPropertyChanged("SelectedCourse"); OnPropertyChanged("SelectedTeacher"); OnPropertyChanged("SelectedRoom"); }