Пример #1
0
        // retreives all information for a booking and reconstructs it into an object
        public static AbstractBooking RetreiveBooking(int bookingId)
        {
            Client                  customer       = null;
            List <Person>           guestList      = new List <Person>();
            int                     customerRef    = DatabaseCalls.GetCustIdForBooking(bookingId);
            CustomerItem            customerItem   = DatabaseCalls.GetCustomersDetails(customerRef).ElementAt(0);
            BusinessFacadeSingleton businessFacade = BusinessFacadeSingleton.Instance();

            customer = businessFacade.CreateClient(customerItem.Id, customerItem.Name, customerItem.Address);

            foreach (var guestItem in DatabaseCalls.GetGuestsDetails(0, bookingId))
            {
                GuestDecorator guest = businessFacade.CreateGuest(guestItem.Name, guestItem.PassportNumber, guestItem.Age);
                if (DatabaseCalls.IsCustomer(guest.Name))
                {
                    guest.SetComponent(customer);
                }
                guestList.Add(guest);
            }
            BookingItem bookingItem = DatabaseCalls.GetBookingDetails(bookingId);
            CarHireItem carHireItem = DatabaseCalls.GetCarHireDetails(bookingId);
            bool        carHire     = false;
            string      driver      = "";
            DateTime    hireStart   = DateTime.Today;
            DateTime    hireEnd     = DateTime.Today;

            if (carHireItem != null)
            {
                carHire   = true;
                driver    = carHireItem.Driver;
                hireStart = carHireItem.HireStart;
                hireEnd   = carHireItem.HireEnd;
            }
            var booking = businessFacade.CreateBooking(bookingId, bookingItem.Arrival, bookingItem.Departure, customer, guestList,
                                                       bookingItem.ChaletId, bookingItem.EveningMeal, bookingItem.Breakfast, carHire, hireStart,
                                                       hireEnd, driver);

            return(booking);
        }