示例#1
0
        private List <string> TestAvailability(CreateEditScheduleVM schedule)
        {
            // Let's check if all data are available at the given day and times, starting with the teacher
            Course course = new CoursesRepository().Course(schedule.CourseID);

            if (course == null)
            {
                return(new List <string> {
                    "The selected course is invalid."
                });
            }

            Schedule availability = repository.TeacherAvailability(course.TeacherID,
                                                                   schedule.WeekDay,
                                                                   schedule.BeginningTime.ToString(ScheduleConstants.TIME_FORMAT),
                                                                   schedule.EndingTime.ToString(ScheduleConstants.TIME_FORMAT));

            if (availability != null && availability.ID != schedule.ID)
            {
                return(new List <string> {
                    course.Teacher.ToString() + " is not available at the given day and times:",
                    availability.ToString()
                });
            }

            // Then, we can check if the room is available
            Classroom classroom = new ClassroomsRepository().Classroom(schedule.ClassroomID);

            if (classroom == null)
            {
                return(new List <string> {
                    "The selected classroom is invalid."
                });
            }

            availability = repository.ClassroomAvailability(schedule.ClassroomID,
                                                            schedule.WeekDay,
                                                            schedule.BeginningTime.ToString(ScheduleConstants.TIME_FORMAT),
                                                            schedule.EndingTime.ToString(ScheduleConstants.TIME_FORMAT));

            if (availability != null && availability.ID != schedule.ID)
            {
                return(new List <string> {
                    "The classroom " + classroom.Name + " is not available at the given day and times:",
                    availability.ToString()
                });
            }

            // Finally, let's check if all the students are available for the lesson
            foreach (string studentId in schedule.Students)
            {
                availability = repository.StudentAvailability(studentId,
                                                              schedule.WeekDay,
                                                              schedule.BeginningTime.ToString(ScheduleConstants.TIME_FORMAT),
                                                              schedule.EndingTime.ToString(ScheduleConstants.TIME_FORMAT));

                if (availability != null && availability.ID != schedule.ID)
                {
                    return(new List <string> {
                        new UsersRepository().UserById(studentId).ToString() + " is not available at the given day and times:",
                        availability.ToString()
                    });
                }
            }

            return(new List <string>());
        }