// logic for confirm booking button. Creates a booking object and saves all its details in the database private void btnConfirmBooking_Click(object sender, RoutedEventArgs e) { if (guests.Count == 0) { MessageBox.Show("Please enter guests."); return; } if (comBoxChaletId.SelectedItem == null) { MessageBox.Show("Please choose a chalet."); return; } if (checkBoxCarHire.IsChecked == true) { if (datePickerCarFrom.SelectedDate == null || datePickerCarTo.SelectedDate == null || comBoxDriver.SelectionBoxItem.ToString() == String.Empty) { MessageBox.Show("Please provide all car hire details."); return; } } if (client == null) { MessageBox.Show("Please provide client's details."); return; } var facade = BusinessFacadeSingleton.Instance(); DateTime startDate = datePickerStartDate.SelectedDate.Value.Date; DateTime endDate = datePickerEndDate.SelectedDate.Value.Date; bool eveningMeal = checkBoxEvMeals.IsChecked.Value; bool breakfast = checkBoxBreakfast.IsChecked.Value; bool carHire = checkBoxCarHire.IsChecked.Value; DateTime hireStart = DateTime.Today; DateTime hireEnd = DateTime.Today; string driver = comBoxDriver.SelectionBoxItem.ToString(); int chaletId = Convert.ToInt32(comBoxChaletId.SelectionBoxItem.ToString()); int bookingRef = DataLayerFacade.GetNextBookingRef(); if (existingClient != null) // sets the client as an existing client to avoid duplicaiton { client = existingClient; } AbstractBooking booking = facade.CreateBooking(bookingRef, startDate, endDate, client, guests, chaletId, eveningMeal, breakfast, carHire, hireStart, hireEnd, driver); DataLayerFacade.SaveBooking(booking, breakfast, eveningMeal); // add the booking to the database Reset(); MessageBox.Show("The booking has been created. The booking reference number is: " + booking.BookingRefNo); this.Close(); }