/// <summary>
        /// Add a new booking
        /// </summary>
        /// <param name="custRefNum"></param>
        /// <param name="arrivalDate"></param>
        /// <param name="departureDate"></param>
        /// <param name="bookingChalet"></param>
        /// <param name="bookingCar"></param>
        /// <param name="guests"></param>
        /// <returns></returns>
        public Booking AddBooking(int custRefNum, DateTime arrivalDate, DateTime departureDate, Chalet bookingChalet, CarHire bookingCar, List <Guest> guests)
        {
            // Create a new booking object using the booking factory method
            Booking book = _bookFactory.FactoryMethod();

            // Set the booking attributes using the inputs provided
            book.Arrival        = arrivalDate;
            book.Departure      = departureDate;
            book.BookingChalet  = bookingChalet;
            book.BookingCarHire = bookingCar;
            book.BookingGuests  = new List <Guest>(guests);
            book.CustomerRef    = custRefNum;
            book.BookingInvoice = new Invoice(book);

            // get all the customers bookings, add to new list, add booking to list, set bookings to new list
            // Create a temporary list of bookings
            List <Booking> tempBookings;

            // Loop through the list of customers
            for (int i = 0; i < _customers.Count; i++)
            {
                // If the current customer reference number matches the input customer reference number
                if (_customers[i].RefNumber == custRefNum)
                {
                    // If the current customer has existing bookings
                    if (_customers[i].Bookings.Count > 0)
                    {
                        // Set the temporary list of bookings to the customer list of bookings
                        tempBookings = new List <Booking>(_customers[i].Bookings);
                    }
                    else
                    {
                        // Create a new list of bookings
                        tempBookings = new List <Booking>();
                    }
                    // Add the newly created booking to the temporary list of bookings
                    tempBookings.Add(book);
                    // Set the customer list of bookings to the temporary list of bookings
                    _customers[i].Bookings = tempBookings;
                    break;
                }
            }
            return(book);
        }
 /// <summary>
 /// Edit a booking
 /// </summary>
 /// <param name="custBookRef"></param>
 /// <param name="custRefNum"></param>
 /// <param name="arrivalDate"></param>
 /// <param name="departureDate"></param>
 /// <param name="bookingChalet"></param>
 /// <param name="bookingCar"></param>
 /// <param name="guests"></param>
 public void EditBooking(int custBookRef, int custRefNum, DateTime arrivalDate, DateTime departureDate, Chalet bookingChalet, CarHire bookingCar, List <Guest> guests)
 {
     // Loop through each customer in the customer list
     for (int i = 0; i < _customers.Count; i++)
     {
         // If the current customer reference number matches the input customer reference number
         if (_customers[i].RefNumber == custRefNum)
         {
             // Loop through each booking in the current customers list of bookings
             for (int j = 0; j < _customers[i].Bookings.Count; j++)
             {
                 // If the current booking matches the booking reference input provided
                 if (_customers[i].Bookings[j].BookingRef == custBookRef)
                 {
                     // Set the attributes of the booking to the inputs provided
                     _customers[i].Bookings[j].Arrival        = arrivalDate;
                     _customers[i].Bookings[j].Departure      = departureDate;
                     _customers[i].Bookings[j].BookingChalet  = bookingChalet;
                     _customers[i].Bookings[j].BookingCarHire = bookingCar;
                     _customers[i].Bookings[j].BookingGuests.Clear();
                     _customers[i].Bookings[j].BookingGuests  = new List <Guest>(guests);
                     _customers[i].Bookings[j].BookingInvoice = new Invoice(_customers[i].Bookings[j]);
                     break;
                 }
             }
         }
     }
 }
Example #3
0
 /// <summary>
 /// Edit a Booking
 /// </summary>
 /// <param name="custBookRef"></param>
 /// <param name="custRefNum"></param>
 /// <param name="arrivalDate"></param>
 /// <param name="departureDate"></param>
 /// <param name="bookingChalet"></param>
 /// <param name="bookingCar"></param>
 /// <param name="guests"></param>
 public void EditBooking(int custBookRef, int custRefNum, DateTime arrivalDate, DateTime departureDate, Chalet bookingChalet, CarHire bookingCar, List <Guest> guests)
 {
     _dataStorage.EditBooking(custBookRef, custRefNum, arrivalDate, departureDate, bookingChalet, bookingCar, guests);
 }