internal Reservation(BookingPeriod bookingPeriod, ClientInfo client, Room room, int guestsCount) { ValidateGuestsCount(room, guestsCount); this.PrimaryClientInfo = client; this.BookingPeriod = bookingPeriod; this.Room = room; this.GuestsCount = guestsCount; }
public bool TryBook(BookingPeriod period, Person person, Room room, int guestCount) { var reservation = new Reservation(period, new ClientInfo(person), room, guestCount); bool canBook = this.IsRoomAvailableForPeriod(reservation.Room.Type, reservation.BookingPeriod); if (!canBook && this.IsOpen) { return(canBook); } this._reservations.Add(reservation); return(canBook); }
private bool IsPeriodAvailable(BookingPeriod bookingPeriod) => this.Reservations.All(x => !x.BookingPeriod.OverlapWith(bookingPeriod));
public bool IsRoomAvailableForPeriod(RoomType roomType, BookingPeriod bookingPeriod) => !this.Reservations.Any() || this.Reservations.Where(x => x.Room.Type == roomType && IsPeriodAvailable(bookingPeriod)).Any();
public bool OverlapWith(BookingPeriod bookingPeriod) => this.CheckIn.Date <bookingPeriod.CheckOut.Date && this.CheckOut.Date> bookingPeriod.CheckIn.Date;