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

        #region [ Constructors ]

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

                this.SetFieldsFrom(BaseRecord);

                this.MovieExemplars = BaseRecord.MovieExemplars;
            }
            else // initialize default fields
            {
                this.FirstRelease = DateTime.MinValue;
                this.Duration     = TimeSpan.MinValue;
                this.Genre        = Genre.None;

                // Add default relationships:
                //
                this.Actors    = new List <MovieActor> ();
                this.Directors = new List <string> ();
                this.Writers   = new List <string> ();

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

        #region [ Public Methods ]

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

            Database = database;

            ID = Database.NextMovieID;

            this.MovieExemplars = new MovieExemplarCollection(this);

            LockProperties();  // make record immutable

            Database.Movies.Add(this);

            return(this);
        }