/*
         * Returns the PersonDecorator's customer number (-1 if the root
         * component is not a concrete Person)
         */
        public override int GetCustNb()
        {
            int custNb = -1;

            if (decoratedComponent != null)
            {
                custNb = decoratedComponent.GetCustNb();
            }

            return(custNb);
        }
Esempio n. 2
0
        // METHODS:

        /*
         * Constructor.
         *
         * throws ArgumentException if bookingNb is not strictly greater
         * than 0, if departure day is not strictly later than arrival
         * day, or if customer is not decorated as a customer.
         */
        public Booking(int bookingNb,
                       PersonComponent customer,
                       DateTime arrival,
                       DateTime departure)
        {
            if (customer.GetCustNb() <= 0)
            {
                throw new ArgumentException("Booking.cust must be"
                                            + "  decorated as a Customer");
            }

            if (bookingNb <= 0)
            {
                throw new ArgumentException("Booking.bookingNb must be"
                                            + " strictly greater than 0");
            }

            if (departure.DayOfYear <= arrival.DayOfYear &&
                departure.Year <= arrival.Year)
            {
                throw new ArgumentException("departure day must be strictly"
                                            + " later than arrival day");
            }

            this.bookingNb = bookingNb;
            this.cust      = customer;
            this.arrival   = arrival;
            this.departure = departure;
        }
        /*
         * Returns a reference to the updated PersonComponent instance.
         */
        public PersonComponent UpdateCustomer(PersonComponent customer,
                                              String newName,
                                              String newAddress)
        {
            // create a fresh customer with the new values but same customerNb
            PersonComponent p = new Person(newName);
            PersonDecorator c = new Customer(newAddress, customer.GetCustNb());

            c.SetComponent(p);

            // get all decorators of customer being updated
            List <PersonDecorator> decorators;

            customer.Unwrap(out decorators);

            // decorate the new customer with those decorators except those
            // of type 'Customer'
            foreach (PersonDecorator decorator in decorators)
            {
                if (decorator.GetType() != typeof(Customer))
                {
                    decorator.SetComponent(c);
                    c = decorator;
                }
            }

            return(c);
        }
 /*
  * Returns a list of all the booking numbers persisted on disc made
  * by a given customer.
  */
 public List <int> GetAllBookingNbs(PersonComponent customer)
 {
     return(dpFacade.GetAllBookingNbs(customer.GetCustNb()));
 }