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");
        }
        public object GetAllTeachersAvailableForSlotForASubject(string PeriodNo, int SubjectId)
        {
            using (SqlConnection Connection = new SqlConnection(ConnectionInformation))
            {
                try
                {
                    Connection.Open();
                    string AvailablityTeachers = "select distinct u.Id,u.Name,s.Period_No from users u left join slot s on u.Id = s.Teacher_Id " +
                                                 "left join Teacher_Subject t on u.Id = t.Teacher_Id WHERE t.Subject_Id = @Subject_Id ";
                    SqlCommand QueryCommand = new SqlCommand(AvailablityTeachers, Connection);
                    QueryCommand.Parameters.AddWithValue("@Subject_Id", SubjectId);

                    SqlDataReader            reader   = QueryCommand.ExecuteReader();
                    List <AvailableTeachers> entities = new List <AvailableTeachers>();
                    while (reader.Read())
                    {
                        AvailableTeachers user = new AvailableTeachers()
                        {
                            Id        = Convert.ToInt32(reader["Id"]),
                            Name      = Convert.ToString(reader["Name"]),
                            Period_No = Convert.ToString(reader["Period_No"]),
                        };
                        entities.Add(user);
                    }
                    foreach (var entry in entities.ToList())
                    {
                        if (entry.Period_No == PeriodNo)
                        {
                            foreach (var user in entities.ToList())
                            {
                                if (user.Id == entry.Id)
                                {
                                    entities.Remove(user);
                                }
                            }
                        }
                    }
                    var result = entities.GroupBy(X => X.Id).Select(x => x.First());
                    reader.Close();
                    if (!result.Any())
                    {
                        return("No Teachers available");
                    }
                    else
                    {
                        return(result);
                    }
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
                finally
                {
                    Connection.Close();
                }
            }
        }
        /// <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);
                }
            }
        }
 /// <summary>
 /// Assistant method that clears all the ViewModel properties
 /// </summary>
 private void ResetData()
 {
     AvailableSearchChoices.Clear();
     LessonsTableData.Clear();
     AvailableClasses.Clear();
     AvailableCourses.Clear();
     AvailableTeachers.Clear();
     AvailableRooms.Clear();
     SelectedLesson       = null;
     SelectedSearchChoice = NOT_ASSIGNED;
     SelectedTeacher      = NOT_ASSIGNED;
     SelectedClass        = NOT_ASSIGNED;
     LessonFirstDay       = NOT_ASSIGNED;
     LessonSecondDay      = NOT_ASSIGNED;
     LessonThirdDay       = NOT_ASSIGNED;
     LessonFourthDay      = NOT_ASSIGNED;
     LessonFirstHour      = NOT_ASSIGNED;
     LessonSecondHour     = NOT_ASSIGNED;
     LessonThirdHour      = NOT_ASSIGNED;
     LessonFourthHour     = NOT_ASSIGNED;
 }
        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");
        }