/// <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)); }
internal Reservability(Table reservable, DateTime inspectionDateTime, TimeSpan duration, Reservation previousReservation, Reservation nextReservation) { _reservable = reservable; _inspectionDateTime = Reservability.getDateTimeZeroed(inspectionDateTime); _duration = duration; _previousReservation = previousReservation; _nextReservation = nextReservation; }