/*
         * Deletes the guest at given index in list of guests for the
         * current booking.
         * Undecorates that guest if if it is also a
         * customer and updates CurrentCustomer with the correct
         * memory reference.
         */
        public void DeleteGuest(int index)
        {
            // First unwrap guest decorator from current customer if they are
            // the guest being deleted:
            if (CurrentBook.GetGuests().ElementAt(index).IsCustomer())
            {
                List <PersonComponent> savedGuests = CurrentBook.GetGuests();
                DateTime arrival;
                DateTime departure;
                CurrentBook.GetDates(out arrival, out departure);

                CurrentCust = CurrentCust.UndecorateOnce();
                CurrentBook = bFact.UpdateBooking(CurrentBook.GetBookingNb(),
                                                  CurrentCust,
                                                  arrival,
                                                  departure);

                foreach (PersonComponent g in savedGuests)
                {
                    CurrentBook.GetGuests().Add(g);
                }
            }

            // Then delete selected guest reference from guests list:
            CurrentBook.GetGuests().RemoveAt(index);
        }
        /*
         * Updates given customer's details with new values for all bookings
         * of his.
         */
        public void UpdateCurrentCustomer(String newName, String newAddress)
        {
            BookingComponent                    processedBooking;
            List <PersonComponent>              savedGuests;
            List <BookingDecorator>             decorationStack;
            List <Dictionary <String, String> > bookingData;
            DateTime arrival;
            DateTime departure;

            // update values within all persisted bookings made by current
            // customer
            foreach (int bookingNb
                     in dpFacade.GetAllBookingNbs(CurrentCust.GetCustNb()))
            {
                dpFacade.Read(bookingNb, out bookingData);

                processedBooking = bFact.Restore(bookingData)
                                   .Unwrap(out decorationStack);

                savedGuests = processedBooking.GetGuests();

                processedBooking.GetDates(out arrival, out departure);

                processedBooking = bFact.UpdateBooking(
                    processedBooking.GetBookingNb(),
                    pFact.UpdateCustomer(
                        processedBooking.GetCustomer(),
                        newName,
                        newAddress),
                    arrival,
                    departure);

                if (decorationStack != null)
                {
                    foreach (BookingDecorator reference in decorationStack)
                    {
                        reference.Setcomponent(processedBooking);
                        processedBooking = reference;
                    }
                }

                foreach (PersonComponent g in savedGuests)
                {
                    processedBooking.AddGuest(g);
                }

                CurrentCust = processedBooking.GetCustomer();
                dpFacade.Persist(processedBooking);
            }

            // reload current booking into the system to upload changes
            if (IsABookingLoaded())
            {
                RestoreBooking(CurrentBook.GetBookingNb());
            }
        }
        /*
         * Returns the current booking's booking number, or -1 if no booking
         * is currently loaded.
         */
        public int GetCurrentBookNb()
        {
            int currentBookingNb = -1;

            if (CurrentBook != null)
            {
                currentBookingNb = CurrentBook.GetBookingNb();
            }
            return(currentBookingNb);
        }
        /*
         * Adds current customer to current booking's list of guests.
         */
        public void AddCustomerToGuests(String passportNb, int age)
        {
            List <PersonComponent> savedGuests = CurrentBook.GetGuests();
            DateTime arrival;
            DateTime departure;

            CurrentBook.GetDates(out arrival, out departure);

            CurrentCust = pFact.GetNewGuest(CurrentCust,
                                            passportNb,
                                            age);
            CurrentBook = bFact.UpdateBooking(CurrentBook.GetBookingNb(),
                                              CurrentCust,
                                              arrival,
                                              departure);

            foreach (PersonComponent g in savedGuests)
            {
                CurrentBook.GetGuests().Add(g);
            }

            CurrentBook.AddGuest(CurrentCust);
        }