예제 #1
0
        /// <summary>
        /// Determines whether this instance and a specified object are the same.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>true if obj type is the same and they have same IDs;
        /// otherwise, false.</returns>
        ///
        public override bool Equals(object obj)
        {
            // Return false if obj is either null or if it is not of
            // the same type as our instance.
            //
            RentedItem otherPrice = obj as RentedItem;

            if (obj == null)
            {
                return(false);
            }

            // Two rented items are same if they belongs to the same customer
            // and points to the same movie exemplar.
            //
            return(this.RentedTo == otherPrice.RentedTo &&
                   this.Exemplar == otherPrice.Exemplar);
        }
예제 #2
0
        /////////////////////////////////////////////////////////////////////////////////

        #region [ Constructors ]

        /// <summary>
        /// Initializes a new (mutable) instance of the MovieExemplar 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 MovieExemplar(MovieExemplar original = null)
            : base(original, "Movie Exemplar")
        {
            if (!IsNew)    // get fields from original
            {
                this.ID    = original.ID;
                this.Movie = original.Movie;

                this.SetFieldsFrom(BaseRecord);

                this.RentedAsItem = BaseRecord.RentedAsItem;
            }
            else // initialize default fields
            {
                this.Movie        = null;
                this.Media        = Media.DVD;
                this.PriceClass   = PriceClass.OlderMovie;
                this.Released     = DateTime.MinValue;
                this.RentedAsItem = null;
            }
        }