/// <summary>
        /// Determines whether or not a Student can register for a course.
        /// </summary>
        /// <param name="student">The Student to register to the Course.</param>
        /// <param name="course">The Course to register the Student for.</param>
        /// <returns>True if the Student can register for the Course.</returns>
        private bool CanRegisterForCourse(Student student, CourseSchedule courseSchedule)
        {
            bool successful = true;

            TimeSpan startTime = courseSchedule.Schedule.StartTime;
            TimeSpan endTime   = ScheduleTime.GetEndTime(startTime, courseSchedule.Schedule.TimeBlocks);

            if (courseSchedule.ProfessorId == student.PersonId)
            {
                successful = false;
            }
            else if (GetNumberOfStudentsInCourse(courseSchedule) >= courseSchedule.Capacity)
            {
                successful = false;
            }
            else
            {
                foreach (StudentSchedule existingSchedule in student.StudentSchedules.Where(s => s.Enrolled))
                {
                    TimeSpan oldStartTime = existingSchedule.CourseSchedule.Schedule.StartTime;
                    TimeSpan oldEndTime   = ScheduleTime.GetEndTime(oldStartTime, existingSchedule.CourseSchedule.Schedule.TimeBlocks);

                    if (ScheduleTime.TimesOverlap(startTime, endTime, oldStartTime, oldEndTime))
                    {
                        successful = false;
                    }
                }
            }

            return(successful);
        }
Ejemplo n.º 2
0
        public void Test_TimesOverlap_False()
        {
            TimeSpan startTime1 = new TimeSpan(8, 0, 0);
            TimeSpan endTime1   = new TimeSpan(9, 15, 0);
            TimeSpan startTime2 = new TimeSpan(9, 30, 0);
            TimeSpan endTime2   = new TimeSpan(10, 45, 0);

            Assert.False(ScheduleTime.TimesOverlap(startTime1, endTime1, startTime2, endTime2));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Schedule a new time block for a Course.
        /// </summary>
        /// <param name="course">The Course to schedule.</param>
        /// <param name="schedule">The Schedule time the Course will take place over.</param>
        /// <param name="professor">The Person who will be the professor for the class.</param>
        /// <param name="capacity">The total capacity of the Course.</param>
        /// <returns>True if the addition was successful.</returns>
        public bool ScheduleCourse(Course course, Schedule schedule, Person professor, short capacity)
        {
            bool successful = true;

            TimeSpan startTime = schedule.StartTime;
            TimeSpan endTime   = ScheduleTime.GetEndTime(startTime, schedule.TimeBlocks);

            if (capacity <= 0)
            {
                successful = false;
            }
            else
            {
                foreach (CourseSchedule existingSchedule in professor.CourseSchedules)
                {
                    TimeSpan oldStartTime = existingSchedule.Schedule.StartTime;
                    TimeSpan oldEndTime   = ScheduleTime.GetEndTime(oldStartTime, existingSchedule.Schedule.TimeBlocks);

                    if (ScheduleTime.TimesOverlap(startTime, endTime, oldStartTime, oldEndTime))
                    {
                        successful = false;
                    }
                }
            }

            if (successful)
            {
                db.CourseSchedules.Add(new CourseSchedule {
                    Course   = course,
                    Schedule = schedule,
                    Person   = professor,
                    Capacity = capacity
                });
                db.SaveChanges();
            }

            return(successful);
        }