Esempio n. 1
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);
        }
 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
     });
 }
Esempio n. 3
0
        public ActionResult Create(MovieViewModel model)

        {
            try

            {
                if (ModelState.IsValid)

                {
                    var movie = model.ToDomain();

                    movie = _database.Add(movie);

                    return(RedirectToAction(nameof(Index)));
                }
                ;
            } catch (Exception e)

            {
                ModelState.AddModelError("", e.Message);
            };



            return(View(model));
        }
Esempio n. 4
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);
     }
 }
 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);
     }
 }
 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
     });
 }
 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",
     });
 }
Esempio n. 8
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);
            }
        }
 /// <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
     });
 }
 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",
     });
 }
Esempio n. 11
0
        private void OnMovieAdd(object sender, EventArgs e)
        {
            var child = new MovieDetailForm();

            if (child.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //Save Movie
            _database.Add(child.Movie);
            RefreshList();
        }
Esempio n. 12
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
     });
 }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
        }
Esempio n. 16
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);
            }
        }
Esempio n. 17
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);
            }
        }
Esempio n. 18
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
        }