public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            BookingConstraints other = obj as BookingConstraints;

            return(other.StartDate.Equals(StartDate) && other.EndDate.Equals(EndDate) &&
                   other.MaxPricePerNight.Equals(MaxPricePerNight) && other.NbOfBeds == NbOfBeds &&
                   other.SmokingAllowed == SmokingAllowed);
        }
예제 #2
0
        /************
         * BOOKINGS *
         ************/

        public Booking CreateBooking(string hotelName, BookingConstraints constraints, string guestName)
        {
            var hotel = GetHotel(hotelName);
            if (hotel == null)
                throw new ArgumentException("There exists no hotel with the given name.");
            foreach (RoomDetails rd in hotel.GetFreeRooms(constraints.StartDate, constraints.EndDate))
            {
                if (rd.SmokingAllowed.Equals(constraints.SmokingAllowed)
                    && constraints.NbOfBeds <= rd.NbOfBeds
                    && constraints.MaxPricePerNight >= rd.PricePerNight)
                {
                    return new Booking
                    {
                        Guest = guestName,
                        StartDate = constraints.StartDate,
                        EndDate = constraints.EndDate,
                        RoomNb = rd.RoomNb,
                        HotelName = hotel.Name,
                        Price = calc.CalculatePrice(rd.PricePerNight, constraints.StartDate, constraints.EndDate)
                    };
                }
            }
            throw new BookingException("No room to satisfy the given booking constraints.");
        }
예제 #3
0
 public ActionResult CreateBooking(string hotelName, BookingConstraints constraints, string guest)
 {
     try
     {
         Booking b = bk.CreateBooking(hotelName, constraints, guest);
         PlannedTrip trip = Session["trip"] as PlannedTrip ?? new PlannedTrip();
         trip.TentativeBookings.Add(b);
         Session["trip"] = trip;
         return RedirectToAction("Index");
     }
     catch (Exception e)
     {
         ModelState.AddModelError(String.Empty, e.Message);
         return View();
     }
 }