Exemplo n.º 1
0
        public bool Book(Slot bookedSlot)
        {
            TimePoint bookedTimePoint = bookedSlot.StartPoint;
            int       durationMinute  = bookedSlot.DurationMinute;

            FreeTime freeTime = null;

            AvailableList.ForEach(time =>
            {
                List <TimePoint> availableSlots = time.CalculateAvailableSlots(durationMinute);
                if (availableSlots.Find(point => point.Equals(bookedTimePoint)) != null)
                {
                    freeTime = time;
                }
            });

            if (freeTime == null)
            {
                //Console.WriteLine("There is no available time for you");
                return(false);
            }

            AvailableList.Remove(freeTime);
            AvailableList.AddRange(freeTime.SplitFreeTimes(bookedSlot));
            AvailableList.Sort((ft1, ft2) => ft1.Start.GetMinuteLength() - ft2.Start.GetMinuteLength());

            BookedList.Add(bookedSlot);
            BookedList.Sort((slot1, slot2) => slot1.StartPoint.GetMinuteLength() - slot2.StartPoint.GetMinuteLength());

            //Console.WriteLine("You have booked successfully");
            return(true);
        }
Exemplo n.º 2
0
        public List <FreeTime> SplitFreeTimes(Slot slot)
        {
            List <FreeTime> result = new List <FreeTime>();

            FreeTime first = new FreeTime {
                Start = this.Start.Clone(), End = slot.StartPoint.Clone()
            };
            FreeTime second = new FreeTime {
                Start = slot.EndPoint.Clone(), End = this.End.Clone()
            };

            if (first.GetDurationMinute() > 0)
            {
                result.Add(first);
            }

            if (second.GetDurationMinute() > 0)
            {
                result.Add(second);
            }

            return(result);
        }