Exemplo n.º 1
0
        /// <summary>
        /// Given a list of reservations and a reservable item return the availability
        /// for the given date/time. The reservable item has been reserved by the reservations
        /// in the list.
        /// </summary>
        /// <param name="reservations"></param>
        /// <param name="reservable"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public Reservability GetReservability(IList <Reservation> reservations, Table reservable, DateTime dateTime, Reservation excludedReservation, TimeSpan newDuration)
        {
            Reservation prev = null;
            Reservation next = null;

            if (reservations != null)
            {
                foreach (Reservation reservation in reservations)
                {
                    if (Reservability.getDateTimeZeroed(reservation.Arrival) < Reservability.getDateTimeZeroed(dateTime))
                    {
                        if (prev == null || ((Reservability.getDateTimeZeroed(prev.Arrival) + prev.Duration) < (Reservability.getDateTimeZeroed(reservation.Arrival) + reservation.Duration)))
                        {
                            if (excludedReservation == null || (!reservation.Equals(excludedReservation)))
                            {
                                prev = reservation;
                            }
                        }
                    }
                    else
                    {
                        if ((next == null || (Reservability.getDateTimeZeroed(next.Arrival) >
                                              Reservability.getDateTimeZeroed(reservation.Arrival))))
                        {
                            if (excludedReservation == null || (!reservation.Equals(excludedReservation)))
                            {
                                next = reservation;
                            }
                        }
                    }
                }
            }
            return(new Reservability(reservable, dateTime, newDuration, prev, next));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds to locations collection of reservations, saves location's state to database.
        /// </summary>
        /// <param name="newReservation"></param>
        public void AddReservation(Reservation newReservation)
        {
            if (newReservation.ReservedList.Count == 0)
            {
                throw new ReservationException("No tables.");
            }

            if (newReservation.GuestCount < 1)
            {
                throw new ReservationException("Guest count cannot be less than one");
            }

            foreach (Table table in newReservation.ReservedList)
            {
                IList <Reservation> reservationsByTable = table.ReservationsThatUseMe;
                Reservability       availability        = this.GetReservability(reservationsByTable, table, newReservation.Arrival, null, newReservation.Duration);
                if (!availability.FullyAvailable)
                {
                    throw new ReservationException(string.Format("Reservation not added because {0} is not available.", table.ToString()));
                }
            }

            newReservation.ParentLocation = this;
            newReservation.Save();
            Reservations.Add(newReservation);

            // cascade
            this.Save();
        }
Exemplo n.º 3
0
 internal Reservability(Table reservable, DateTime inspectionDateTime, TimeSpan duration,
                        Reservation previousReservation, Reservation nextReservation)
 {
     _reservable          = reservable;
     _inspectionDateTime  = Reservability.getDateTimeZeroed(inspectionDateTime);
     _duration            = duration;
     _previousReservation = previousReservation;
     _nextReservation     = nextReservation;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a value that indicates either the number of reservable items available,
        /// or the number of guest seatings available.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="dateTime"></param>
        /// <param name="guest"></param>
        /// <returns></returns>
        private int GetAvailability(Session session, DateTime dateTime, bool guest, TimeSpan duration)
        {
            int total = 0;

            IList <Table> reservables = GetReservables(session, dateTime, duration);

            foreach (Table reservable in reservables)
            {
                Reservability reservability = GetReservability(reservable, dateTime, null, duration);

                if (reservability.FullyAvailable)
                {
                    if (guest)
                    {
                        total += reservable.MaxGuests;
                    }
                    else
                    {
                        total++;
                    }
                }
            }
            return(total);
        }