/// <summary> /// Update the Dictionary of Available rooms /// </summary> /// <param name="roomList"></param> private void UpdateCachedRoomList(List <RoomInfo> roomList) { foreach (RoomInfo room in roomList) { // Remove room from cached room list if it got closed, became invisible or was marked as removed if (room.RemovedFromList) { if (AvailableRooms.ContainsKey(room.Name)) { AvailableRooms.Remove(room.Name); } continue; } // Add new room info to cache if (!AvailableRooms.ContainsKey(room.Name)) { AvailableRooms.Add(room.Name, room); } // Update cached RoomInfo else { AvailableRooms[room.Name] = room; } } }
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); } } }
private void ShowAvailableRooms() { if ((SelectedDate != null) && (SelectedArea != null) && (MeetingStart != null) && (MeetingEnd != null)) { AvailableRooms.Clear(); foreach (Room r in Database.GetAvailableRooms(SelectedArea, MeetingStart, MeetingEnd.Value, CurrentMeetingId)) { AvailableRooms.Add(r); } } }
private void LoadAvailableRooms() { List <RoomPlan> roomPlans = new List <RoomPlan>(); foreach (var roomPlanAssignment in ProjectFile.RoomPlans.ToList()) { if (roomPlanAssignment.RoomPlan != null) { roomPlans.Add(roomPlanAssignment.RoomPlan); } } AvailableRooms.Clear(); AvailableRooms.Add(roomPlans); }
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"); }
async Task ExecuteSearchAvailableRoomsCommand() { if (NewReservation.StartingTime > NewReservation.EndingTime) { await Application.Current.MainPage.DisplayAlert("Something is wrong", "A reservation cannot finish before it starts!", "OK"); return; } if (IsBusy) { return; } IsBusy = true; try { var reservationTable = await CloudService.GetTableAsync <Reservation>(); var listOfReservations = await reservationTable.ReadAllReservationsAsync(); var roomTable = await CloudService.GetTableAsync <Room>(); var listOfRooms = await roomTable.ReadAllRoomsAsync(); AvailableRooms.Clear(); //inserts all the rooms in the collection, then removes the ones which are arleady reserved foreach (Room room in listOfRooms) { AvailableRooms.Add(room); SortRooms(AvailableRooms, room); foreach (Reservation reservation in listOfReservations) { if (reservation.RoomName.Equals(room.Name)) { if (reservation.Date.Date.Equals(NewReservation.Date.Date)) { if ((TimeSpan.Compare(reservation.StartingTime, NewReservation.EndingTime) == -1 && TimeSpan.Compare(reservation.EndingTime, NewReservation.EndingTime) == 1) || (TimeSpan.Compare(reservation.StartingTime, NewReservation.StartingTime) == -1 && TimeSpan.Compare(reservation.EndingTime, NewReservation.StartingTime) == 1) || (TimeSpan.Compare(reservation.StartingTime, NewReservation.StartingTime) == 1 && TimeSpan.Compare(reservation.EndingTime, NewReservation.EndingTime) == -1)) { AvailableRooms.Remove(room); break; } } } } } } catch (Exception ex) { Debug.WriteLine($"[ReservationListViewModel] Save error: {ex.Message}"); } finally { IsBusy = false; } }