Exemple #1
0
        /////////////////////////////////////////////////////////////////////////////////

        #region [ Constructors ]

        /// <summary>
        /// Initializes a new (mutable) instance of the Customer class either as an empty
        /// (without argument) or as a copy-constructed object from an existing
        /// (immutable) instance from database.
        /// See also <see cref="AddTo"/> and <see cref="Update"/> methods.
        /// </summary>
        /// <remarks>
        /// The constructor does not insert or update database. To save changes to
        /// database, use either <see cref="AddTo"/> method after construction without
        /// original object, or <see cref="Update"/> method after copy-construction
        /// from an existing original immutable object. Initially constructed objects
        /// are all mutable until *saved to database*, after which they become immutable.
        /// To modify immutable object one must copy-construct new instance and later
        /// call <see cref="Update"/> to commit changes. This ensures transactioncal
        /// change of all records and proper delivery of on-changed events to event
        /// handlers.
        /// </remarks>
        ///
        public Customer(Customer original = null)
            : base(original, "Customer")
        {
            if (!IsNew)    // get fields from original
            {
                this.ID = original.ID;

                this.SetFieldsFrom(BaseRecord);

                this.RentedItems = BaseRecord.RentedItems;
            }
            else // initialize default fields
            {
                this.Membership = Membership.NotMember;

                // Note: we should not instantiate this.RentedItems collection
                // as we are still not connected to database. Instantiation is delayed
                // until AddTo() is called.
                //
                this.RentedItems = null;
            }
        }
Exemple #2
0
        /////////////////////////////////////////////////////////////////////////////////

        #region [ Public Methods ]

        /// <summary>
        /// Inserts newly created instance into database.
        /// </summary>
        ///
        public Customer AddTo(VideoRentalOutlet database)
        {
            VerifyAddTo(database);

            Database = database;

            Customer customerWithPID = Database.Customers.FindByPersID(PersonID);

            if (customerWithPID != null && customerWithPID != this)
            {
                throw new ArgumentException("Customer with the same Person-ID "
                                            + "already exists in database.");
            }

            ID = Database.NextCustomerID;

            this.RentedItems = new RentedItems(this);

            LockProperties();  // make record immutable

            Database.Customers.Add(this);

            return(this);
        }
Exemple #3
0
 public static void EmptyBasket()
 {
     RentedItems.Clear();
     PurchasedItems.Clear();
 }
Exemple #4
0
 public static void AddRentableItem(Movie item)
 {
     RentedItems.Add(item);
 }