Пример #1
0
 /// <summary>Seeds a database.</summary>
 /// <param name="source">The database to seed.</param>
 /// <param name="movies">The movies to seed with.</param>
 /// <remarks>
 /// Extension method to see a database.
 /// </remarks>
 public static void Seed(this IMovieDatabase source, Movie[] movies)
 {
     foreach (var movie in movies)
     {
         source.Add(movie);
     }
 }
Пример #2
0
        /// <summary>Seeds a database.</summary>
        /// <param name="database">The database to seed.</param>
        /// <remarks>
        /// Assumes the database is empty.
        /// </remarks>
        public static void Seed(this IMovieDatabase database)
        {
            var movie1 = new Movie()
            {
                Title       = "Jaws",
                Description = "The original shark movie",
                Rating      = "PG",
                ReleaseYear = 1979,
                RunLength   = 123
            };

            var movie2 = new Movie()
            {
                Title       = "Jaws 2",
                Rating      = "PG-13",
                ReleaseYear = 1981,
                RunLength   = 156,
            };

            var movie3 = new Movie()
            {
                Title       = "Dune",
                Rating      = "PG",
                ReleaseYear = 1985,
                RunLength   = 210
            };

            database.Add(movie1);
            database.Add(movie2);
            database.Add(movie3);
        }
Пример #3
0
 public static void Seed(this IMovieDatabase source, Movie[] movies)   //to qualify extention method: in static class, members are public and static, "this" before first parameter named "source"
 {
     foreach (var movie in movies)
     {
         source.Add(movie);
     }
 }
Пример #4
0
        //Make static because it does not reference any instance data
        //nor does it really need to be created
        //Converting to an extension method
        //  1. Must be in a static class (public or internal) [extension methods do not work outside of static class]
        //  2. Must accept as a first parameter the type to extend
        //  3. First parameter must be preceded by keyword 'this'
        //  4. (optional) Change first parameter to 'source'
        public static void Seed(this IMovieDatabase source)    //database.Seed()
        {
            //Extension methods - DO NOT check for null

            //Not needed here- clears all items from list
            // _movies.Clear();

            //Seed database
            // Object initializer (syntax) - only usable on new operator
            // Limitations
            //     1. Can only set properties with setters
            //     2.  Can set properties that are themselves new'ed up but cannot set child properties
            //        Position = new Position () { Name = "Boss" }; allowed
            //            Position.Title = "Boss"; not allowed
            //     3. Properties cannot rely on other properties
            //         Description = "blah",
            //         FullDescription = Description

            //Collection initializer syntax. compiler can infer the type based on the types in the initializer (only arrays)
            var items = new[] {     //new Movie[] {
                new Movie()
                {
                    Name        = "Jaws",
                    ReleaseYear = 1977,
                    RunLength   = 190,
                    Description = "Shark movie",
                    IsClassic   = true,
                    Rating      = "PG", // Can have a comma at end
                },
                new Movie()
                {
                    Name        = "Jaws 2",
                    ReleaseYear = 1979,
                    RunLength   = 195,
                    Description = "Shark movie",
                    IsClassic   = true,
                    Rating      = "PG-13",
                },
                new Movie()
                {
                    Name        = "Dune",
                    ReleaseYear = 1985,
                    RunLength   = 220,
                    Description = "Based on book",
                    IsClassic   = true,
                    Rating      = "PG",
                }
            };

            //TODO: FIX error handling
            foreach (var item in items)
            {
                source.Add(item);
            }
        }
Пример #5
0
 /// <summary>Seeds the database.</summary>
 /// <param name="source">The source.</param>
 public static void Seed(this IMovieDatabase source)
 {
     source.Add(new Movie()
     {
         Id          = 1,
         Title       = "Example Title Seed",
         Description = "Example Description Seed",
         Length      = 100,
         IsOwned     = true
     });
 }
Пример #6
0
        private IMovieDatabase _database; // = new MovieLib.Data.Memory.SqlMovieDatabase();

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var connString = ConfigurationManager.ConnectionStrings["MovieDatabase"].ConnectionString;

            _database = new MovieLib.Data.Memory.SqlMovieDatabase(connString);

            _dgvMovies.AutoGenerateColumns = false;

            RefreshList();
        }
Пример #7
0
        /// <summary>Get a movie by title.</summary>
        /// <param name="source">The source.</param>
        /// <param name="title">The movie title.</param>
        /// <returns>The movie, if found.</returns>
        public static Movie GetByTitle(this IMovieDatabase source, string title)
        {
            foreach (var item in source.GetAll())
            {
                if (String.Compare(item.Title, title, true) == 0)
                {
                    return(item);
                }
            }
            ;

            return(null);
        }
        //This method MUST be overridden in a derived type
        //protected abstract void SomeAbstractFunction();


        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var connString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;

            _database = new SqlMovieDatabase(connString);

            //Seed database
            //SeedDatabase.Seed(_database);
            //_database.Seed();

            _listMovies.DisplayMember = "Name"; // Setting the Display Member Property to Name property. (When it displays it looks for the name property to display)
            RefreshMovies();
        }
 public static void Seed(this IMovieDatabase source)
 {
     source.Add(new Movie()
     {
         Title = "Jaws", ReleaseYear = 1979, Rating = "PG", RunLength = 156
     });
     source.Add(new Movie()
     {
         Title = "Jaws 2", ReleaseYear = 1981, Rating = "PG-13", RunLength = 200
     });
     source.Add(new Movie()
     {
         Title = "Star Wars", ReleaseYear = 1977, Rating = "PG", RunLength = 164
     });
 }
Пример #10
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //seed movies
            var connString = ConfigurationManager.ConnectionStrings["MovieDatabase"];

            //_movies = new FileMovieDatabase (@"movies.csv");
            _movies = new SqlMovieDatabase(connString.ConnectionString);
            //var count = _movies.GetAll ().Count ();
            //if (count == 0)
            //MovieDatabaseExtensions.Seed (_movies);
            //_movies.Seed ();

            UpdateUI();
        }
 public static void Seed(this IMovieDatabase source)
 {
     source.Add(new Movie()
     {
         Title   = "Inception",
         IsOwned = true, Length = 128,
     });
     source.Add(new Movie()
     {
         Title   = "batman 3",
         IsOwned = true, Length = 152,
     });
     source.Add(new Movie()
     {
         Title   = "Transformers",
         IsOwned = false, Length = 258
     });
 }
Пример #12
0
        //Make static because it does not reference any instance data
        //Nor does it really need to be created
        //Converting to an extension method
        //1. Must be in a static class (public or internal)
        //2. Must accept as a first parameter the type to extend
        //3. First parameter must be preceded by keyword 'this
        //  4. (Optional) Change first parameter to `source`
        public static void Seed(this IMovieDatabase source)      //database.Seed()
        {
            //Extension methods - DO NOT check for null

            //Not Needed here - clear all item from list
            //_movies.Clear();

            //Collection initializer syntax
            var items = new[] { //new Movie[] {
                new Movie()
                {
                    Name        = "Jaws",
                    ReleaseYear = 1977,
                    RunLength   = 190,
                    Description = "Shark movie",
                    IsClassic   = true,
                    Rating      = "PG", // Can have a comma at end
                },
                new Movie()
                {
                    Name        = "Jaws 2",
                    ReleaseYear = 1979,
                    RunLength   = 195,
                    Description = "Shark movie",
                    IsClassic   = true,
                    Rating      = "PG 13",
                },
                new Movie()
                {
                    Name        = "Dune",
                    ReleaseYear = 1985,
                    RunLength   = 220,
                    Description = "Based on book",
                    IsClassic   = true,
                    Rating      = "PG",
                },
            };

            //TODO: Fix error handling
            foreach (var item in items)
            {
                source.Add(item);
            }
        }
        public static void Seed(this IMovieDatabase source)
        {
            var movies = new[] { // Inferring Array Type and Size, since it is an expression we can return it
                new Movie()
                {
                    Name        = "Dark Knight",
                    RunLength   = 170,
                    ReleaseYear = 2015,
                },
                new Movie()
                {
                    Name        = "Harry Potter",
                    RunLength   = 170,
                    ReleaseYear = 2011,
                },
            };

            Seed(source, movies);
        }
Пример #14
0
        /// <summary>Seeds a database.</summary>
        /// <param name="source">The database to seed.</param>
        /// <remarks>
        /// Extension method to see a database.
        /// </remarks>
        public static void Seed(this IMovieDatabase source)
        {
            var movies = new[] {
                new Movie()
                {
                    Name        = "Jaws",
                    RunLength   = 120,
                    ReleaseYear = 1977,
                },
                new Movie()
                {
                    Name        = "What About Bob?",
                    RunLength   = 96,
                    ReleaseYear = 2004,
                },
            };

            Seed(source, movies);
        }
Пример #15
0
 public static void Seed(this IMovieDatabase source)
 {
     source.Add(new Movie()
     {
         Title = "Jaws", ReleaseYear = 1979, Rating = "PG",
     });
     source.Add(new Movie()
     {
         Title = "StarWars", ReleaseYear = 1977, Rating = "PG",
     });
     source.Add(new Movie()
     {
         Title = "Distance", ReleaseYear = 1989, Rating = "PG",
     });
     source.Add(new Movie()
     {
         Title = "Spy Kids", ReleaseYear = 1999, Rating = "PG-13",
     });
 }
Пример #16
0
        //This method MUST BE defined in a derived type
        //protected abstract void SomeAbstractFunction()

        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>

        protected override void OnLoad(EventArgs e)    //derived method. Start with override keyword
        {
            base.OnLoad(e);

            var connString = ConfigurationManager
                             .ConnectionStrings["Database"]
                             .ConnectionString;

            _database = new SqlMovieDatabase(connString);
            //_database.Add(new Movie());

            //Seed database
            //var seed = new SeedDatabase();
            //SeedDatabase.Seed(_database);  Call SeedDatabase. Type of _database: interface
            //_database.Seed();

            _listMovies.DisplayMember = "Name";
            RefreshMovies();
        }
Пример #17
0
 /// <summary>Adds seed data to a database.</summary>
 /// <param name="source">The data to seed.</param>
 public static void WithSeedData(this IMovieDatabase source)
 {
     source.Add(new Movie()
     {
         Id      = 1, Title = "Saving Private Ryan", Description = "WWII movie with Tom Hanks and Matt Damon", Length = 180,
         IsOwned = true
     });
     source.Add(new Movie()
     {
         Id = 2, Title = "The 5th Element", Length = 120, IsOwned = true
     });
     source.Add(new Movie()
     {
         Id = 3, Title = "What About Bob", Description = "Comedy with Bill Murray", Length = 118, IsOwned = false
     });
     source.Add(new Movie()
     {
         Id = 4, Title = "Crouching Tiger, Hidden Dragon", Length = 145, IsOwned = true
     });
 }
 public static void Seed(this IMovieDatabase source)
 {
     source.Add(new Movie()
     {
         Title       = "Airplane",
         ReleaseYear = 1993,
         Rating      = "R",
     });
     source.Add(new Movie()
     {
         Title       = "Jaws",
         ReleaseYear = 1979,
         Rating      = "PG",
     });
     source.Add(new Movie()
     {
         Title       = "Young Frankenstein",
         ReleaseYear = 1952,
         Rating      = "R",
     });
 }
Пример #19
0
 /// <summary>Seeds the database.</summary>
 /// <param name="source">The source.</param>
 public static void Seed(this IMovieDatabase source)
 {
     source.Add(new Movie()
     {
         Title       = "The Mummy",
         IsOwned     = true,
         Description = "There's a scarry mummy guy who wants to rule the world",
         Length      = 90,
     });
     source.Add(new Movie()
     {
         Title   = "The Incredibles",
         IsOwned = true,
         Length  = 120,
     });
     source.Add(new Movie()
     {
         Title   = "A long movie",
         IsOwned = false,
         Length  = 800
     });
 }
Пример #20
0
        /// <summary>Seeds the database.</summary>
        /// <param name="source">The source.</param>
        public static void Seed(this IMovieDatabase source)
        {
            var message = "";

            source.Add(new Movie()
            {
                Title   = "The Mummy",
                IsOwned = true,
                Length  = 120,
            }, out message);
            source.Add(new Movie()
            {
                Title   = "The Incredibles",
                IsOwned = true,
                Length  = 105,
            }, out message);
            source.Add(new Movie()
            {
                Title   = "Test movie",
                IsOwned = false,
                Length  = 60,
            }, out message);
        }
Пример #21
0
        /// <summary>
        /// Seeds database with sample movies for testing program
        /// </summary>
        /// <param name="source"></param>
        public static void Seed(this IMovieDatabase source)
        {
            var message = "";

            source.Add(new Movie()
            {
                Title  = "Akira",
                Owned  = true,
                Length = 124,
            }, out message);
            source.Add(new Movie()
            {
                Title  = "Shin Godzilla",
                Owned  = true,
                Length = 120,
            }, out message);
            source.Add(new Movie()
            {
                Title  = "End of Evangelion",
                Owned  = true,
                Length = 90
            }, out message);
        }
Пример #22
0
        public static void Seed(this IMovieDatabase source)
        {
            var message = "";

            source.Add(new Movie()
            {
                Name           = "Scarface",
                IsDiscontinued = true,
                Length         = 1500,
            }, out message);
            source.Add(new Movie()
            {
                Name           = "Deadpool",
                IsDiscontinued = true,
                Length         = 15,
            }, out message);
            source.Add(new Movie()
            {
                Name           = "Seven",
                IsDiscontinued = false,
                Length         = 800
            }, out message);
        }
Пример #23
0
        public static void Seed(this IMovieDatabase source)
        {
            var items = new[] {
                new Movie()
                {
                    Name        = "Jaws",
                    ReleaseYear = 1977,
                    RunLength   = 190,
                    Description = "Shark movie",
                    IsClassic   = true,
                    Rating      = "PG",
                },
                new Movie()
                {
                    Name        = "Jaws 2",
                    ReleaseYear = 1979,
                    RunLength   = 195,
                    Description = "Shark movie",
                    IsClassic   = true,
                    Rating      = "PG-13",
                },
                new Movie()
                {
                    Name        = "Dune",
                    ReleaseYear = 1985,
                    RunLength   = 220,
                    Description = "Based on book",
                    IsClassic   = true,
                    Rating      = "PG",
                }
            };

            foreach (var item in items)
            {
                source.Add(item);
            }
        }
Пример #24
0
 public Shop(IMovieDatabase db)
 {
     _db = db;
 }
        //Make static because it does not reference any instance data
        //nor does it really need to be created
        //Converting to an extension method
        //  1. Must be in a static class (public or internal)
        //  2. Must accept as a first parameter the type to extend
        //  3. First parameter must be preceded by keyword `this`
        //  4. (Optional) Change first parameter to `source`
        public static void Seed(this IMovieDatabase source)      //database.Seed()
        {
            //Extension methods - DO NOT check for null

            //Not needed here - clears all items from list
            //_movies.Clear();

            //Collection initializer syntax
            var items = new[] { //new Movie[] {
                new Movie()
                {
                    Name        = "Jaws",
                    ReleaseYear = 1977,
                    RunLength   = 190,
                    Description = "Shark movie",
                    IsClassic   = true,
                    Rating      = "PG", // Can have a comma at end
                },
                new Movie()
                {
                    Name        = "Jaws 2",
                    ReleaseYear = 1979,
                    RunLength   = 195,
                    Description = "Shark movie",
                    IsClassic   = true,
                    Rating      = "PG-13",
                },
                new Movie()
                {
                    Name        = "Dune",
                    ReleaseYear = 1985,
                    RunLength   = 220,
                    Description = "Based on book",
                    IsClassic   = true,
                    Rating      = "PG",
                }
            };

            //TODO: Fix error handling
            foreach (var item in items)
            {
                source.Add(item);
            }

            #region Unused code
            //Seed database
            // Object initializer - only usable on new operator
            //   Limitations:
            //      1. Can only set properties with setters
            //      2. Can set properties that are themselves new'ed up but cannot set child properties
            //                    Position = new Position() { Name = "Boss" };  //Allowed
            //                    Position.Title = "Boss";  //Not allowed
            //      3. Properties cannot rely on other properties
            //               Description = "blah",
            //               FullDescription = Description
            //var movie = new Movie();
            //movie.Name = "Jaws";
            //movie.ReleaseYear = 1977;
            //movie.RunLength = 190;
            //movie.Description = "Shark movie";
            //movie.IsClassic = true;
            //movie.Rating = "PG";
            //var movie = new Movie() {
            //    Name = "Jaws",
            //    ReleaseYear = 1977,
            //    RunLength = 190,
            //    Description = "Shark movie",
            //    IsClassic = true,
            //    Rating = "PG",  // Can have a comma at end
            //};
            //Add(movie, out var error);

            //movie = new Movie() {
            //    Name = "Jaws 2",
            //    ReleaseYear = 1979,
            //    RunLength = 195,
            //    Description = "Shark movie",
            //    IsClassic = true,
            //    Rating = "PG-13",
            //};
            //Add(movie, out error);

            //movie = new Movie() {
            //    Name = "Dune",
            //    ReleaseYear = 1985,
            //    RunLength = 220,
            //    Description = "Based on book",
            //    IsClassic = true,
            //    Rating = "PG",
            //};
            //Add(movie, out error);
            #endregion
        }
Пример #26
0
 public MovieController(IMovieDatabase database)
 {
     _database = database;
 }
Пример #27
0
        // Make static beacuse it does not reference ant inastance data
        // nor does it reall need to be created
        public static void Seed(this IMovieDatabase source)
        {
            {
                // Not needed here
                // _movies.Clear();

                //Collection initializer syntax
                var items = new[] {
                    new Movie()
                    {
                        Name        = "Titanic",
                        ReleaseYear = 1997,
                        RunLength   = 195,
                        Description = "Film about a sinking boat.",
                        IsClassic   = true,
                        Rating      = "PG-13",
                    },


                    new Movie()
                    {
                        Name        = "Fast and Furious",
                        ReleaseYear = 2009,
                        RunLength   = 106,
                        Description = "Film about racing cars",
                        IsClassic   = true,
                        Rating      = "PG-13",
                    }
                };

                // TODO: Fix error Handling
                foreach (var item in items)
                {
                    source.Add(item);
                }


                // Seed Database
                // Object Initializer - only usuable on new operator
                // Limitations
                // 1). Con only set properties with setters
                // 2). Can set properties that are themselves new'd up, but cannot set child properties
                //                        Position = new Position() { Name = "Boss"};  // Allowed
                //                        Position.Title = "Boss";   // Not allowed
                // 3). Properties cannot rely on other properties
                //                     Description = "blah"
                //                     FullDescription = Description
                //var movie = new Movie();
                //movie.Name = "Titanic";
                //movie.ReleaseYear = 1997;
                //movie.RunLength = 195;
                //movie.Description = "Film about a sinking boat.";
                //movie.IsClassic = true;
                //movie.Rating = "PG-13";
                //Add(movie, out var error);
                //    var movie = new Movie() {
                //        Name = "Titanic",
                //        ReleaseYear = 1997,
                //        RunLength = 195,
                //        Description = "Film about a sinking boat.",
                //        IsClassic = true,
                //        Rating = "PG-13",
                //    };
                //    Add(movie, out var error);


                //    movie = new Movie() {
                //        Name = "Fast and Furious",
                //        ReleaseYear = 2009,
                //        RunLength = 106,
                //        Description = "Film about racing cars",
                //        IsClassic = true,
                //        Rating = "PG-13",
                //};
                //    Add(movie, out error);
            }
        }
Пример #28
0
        //Make static because it does not reference any instance data
        //Converting to an extension method
        // 1. Must be in a static class
        // 2. Must accept as a first parameter the type to extend
        // 3. First parameter must be preceded by keyword "this"
        // 4. (Optional) Change first parameter to "source"
        public static void Seed(this IMovieDatabase source)
        {
            //Extension methods - DO NOT check for null

            //Not needed here
            //_movies.Clear();

            //Collections initializer syntax
            var items = new[] { //Movie[] {
                new Movie()
                {
                    Name        = "Jaws",
                    ReleaseYear = 1977,
                    RunLength   = 190,
                    Description = "Shark movie",
                    IsClassic   = true,
                    Rating      = "PG",
                },
                new Movie()
                {
                    Name        = "Shrek",
                    ReleaseYear = 1999,
                    RunLength   = 150,
                    Description = "Ogre movie",
                    IsClassic   = true,
                    Rating      = "PG",
                }
            };

            //TODO: Fix error handling
            foreach (var item in items)
            {
                source.Add(item);
            }
            #region seed database
            //Seed database
            // Object initialize - only usable on new operator
            //  1. Can only set properties with setters
            //  2. Can set properties that are themselves new'ed up but cannot set child properties
            //      Position = new Position() (Name = "Boss" ); //Allowed
            //      Position.Title = "Boss"; //Not allowed
            //  3. Properties cannot rely on other properties
            //      Description = "blah"; Not allowed
            //      FullDescription = Description;
            //var movie = new Movie();
            //movie.Name = "Jaws";
            //movie.ReleaseYear = 1977;
            //movie.RunLength = 190;
            //movie.Description = "Shark movie";
            //movie.IsClassic = true;
            //movie.Rating = "PG";
            //Add(movie, out var error);
            //var movie = new Movie() {
            //    Name = "Jaws",
            //    ReleaseYear = 1977,
            //    RunLength = 190,
            //    Description = "Shark movie",
            //    IsClassic = true,
            //    Rating = "PG",
            //};

            //Add(movie, out var error);

            //movie = new Movie() {
            //    Name = "Shrek",
            //    ReleaseYear = 1999,
            //    RunLength = 150,
            //    Description = "Ogre movie",
            //    IsClassic = true,
            //    Rating = "PG",
            //};

            //Add(movie, out error);
            #endregion
        }
 public MovieController(IMovieDatabase movieDatabase)
 {
     _movieDatabase = movieDatabase;
 }