Esempio n. 1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMoviesContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcMoviesContext> >()))
            {
                // Look for any movies.
                if (context.Movie.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movie.AddRange(
                    new Movie
                {
                    Title       = "The RM",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Price       = 7.99M,
                    Rating      = "PG",
                    ImageSource = "~/images/theRM.jpg"
                },

                    new Movie
                {
                    Title       = "Other Side of Heaven ",
                    ReleaseDate = DateTime.Parse("1984-3-13"),
                    Genre       = "Comedy",
                    Price       = 8.99M,
                    Rating      = "G",
                    ImageSource = "~/images/theOtherSideOfHeaven.jpg"
                },

                    new Movie
                {
                    Title       = "Meet the Mormons",
                    ReleaseDate = DateTime.Parse("1986-2-23"),
                    Genre       = "Comedy",
                    Price       = 9.99M,
                    Rating      = "G",
                    ImageSource = "~/images/meetTheMormons.jpg"
                },

                    new Movie
                {
                    Title       = "The Prince of Egypt",
                    ReleaseDate = DateTime.Parse("1998-4-15"),
                    Genre       = "Animation",
                    Price       = 3.99M,
                    Rating      = "G",
                    ImageSource = "~/images/ThePrinceOfEgypt.jpg"
                }
                    );
                context.SaveChanges();
            }
        }
Esempio n. 2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMoviesContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcMoviesContext> >()))
            {
                // Look for any movies.
                if (context.Movie.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movie.AddRange(
                    new Movie
                {
                    Title       = "When Harry Met Sally",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Price       = 7.99M,
                    Rating      = "R"
                },

                    new Movie
                {
                    Title       = "Ghostbusters ",
                    ReleaseDate = DateTime.Parse("1984-3-13"),
                    Genre       = "Comedy",
                    Price       = 8.99M,
                    Rating      = "R"
                },

                    new Movie
                {
                    Title       = "Ghostbusters 2",
                    ReleaseDate = DateTime.Parse("1986-2-23"),
                    Genre       = "Comedy",
                    Price       = 9.99M,
                    Rating      = "R"
                },

                    new Movie
                {
                    Title       = "Rio Bravo",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Price       = 3.99M,
                    Rating      = "R"
                }
                    );
                context.SaveChanges();
            }
        }
Esempio n. 3
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            //Create MvcMoviesContext context var using DbContextOptions.  context var is basically a Pointer to the DB.
            using (var context = new MvcMoviesContext(serviceProvider.GetRequiredService<DbContextOptions<MvcMoviesContext>>()))
            {
                // Look for any movies in DB
                if (context.Movie.Any())
                {
                    return; //DB already populated
                }

                //Add Movies to Movie Table
                context.Movie.AddRange(
                    new Movie
                    {
                        Title = "When Harry Met Sally",
                        ReleaseDate = DateTime.Parse("1989-2-12"),
                        Genre = "Romantic Comedy",
                        Price = 7.99M
                    },

                    new Movie
                    {
                        Title = "Ghostbusters ",
                        ReleaseDate = DateTime.Parse("1984-3-13"),
                        Genre = "Comedy",
                        Price = 8.99M
                    },

                    new Movie
                    {
                        Title = "Ghostbusters 2",
                        ReleaseDate = DateTime.Parse("1986-2-23"),
                        Genre = "Comedy",
                        Price = 9.99M
                    },

                    new Movie
                    {
                        Title = "Rio Bravo",
                        ReleaseDate = DateTime.Parse("1959-4-15"),
                        Genre = "Western",
                        Price = 3.99M
                    }
                );

                context.SaveChanges();
            }
        }
Esempio n. 4
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMoviesContext(
                       serviceProvider.GetRequiredService <DbContextOptions <MvcMoviesContext> >()))
            {
                if (context.Movie.Any())
                {
                    return;
                }
                context.Movie.AddRange(


                    new Movie
                {
                    Title       = "Jumanji",
                    ReleaseDate = DateTime.Parse("2020-02-20"),
                    Genre       = "Action",
                    Price       = 15,
                    Rating      = "5"
                },
                    new Movie
                {
                    Title       = "Lossing Lerato ",
                    ReleaseDate = DateTime.Parse("2019-02-20"),
                    Genre       = "Thriller",
                    Price       = 14,
                    Rating      = "5"
                },
                    new Movie
                {
                    Title       = "Bad Boys",
                    ReleaseDate = DateTime.Parse("2020-01-10"),
                    Genre       = "Action Thriller",
                    Price       = 10,
                    Rating      = "5"
                },
                    new Movie
                {
                    Title       = "Queen Sono",
                    ReleaseDate = DateTime.Parse("2020-01-05"),
                    Genre       = "Action Thriller",
                    Price       = 15,
                    Rating      = "5"
                }
                    );
                context.SaveChanges();
            }
        }