Exemplo n.º 1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMovieContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcMovieContext> >()))
            {
                // 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",
                    Rating      = "R",
                    Price       = 7.99M
                },

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

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

                    new Movie
                {
                    Title       = "Rio Bravo",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Rating      = "R",
                    Price       = 3.99M
                }
                    );
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static void SeedData(MvcMovieContext context)
        {
            Console.WriteLine("Appling Migrations...");

            context.Database.Migrate();

            // Look for any movies.
            if (context.Movie.Any())
            {
                Console.WriteLine("Already have data - not seeding.");

                return;   // DB has been seeded
            }

            Console.WriteLine("Adding data - seeding...");

            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();
        }
Exemplo n.º 3
0
        public IActionResult Add([Bind("FirstName", "LastName", "Username", "Password")] Customer customer)
        {
            string Message = $"Successful page visit at {DateTime.UtcNow.ToLongTimeString()}";

            _logger.LogInformation(Message);
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                _context.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Exemplo n.º 4
0
        // ADD to Cart:
        public void AddToCart(Movie movie)
        {
            var shoppingCartItem =
                _mvcMovieContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Movie.Id == movie.Id && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Movie          = movie
                };

                _mvcMovieContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            ///else
            ///{
            ///    shoppingCartItem.Amount++;
            ///}

            _mvcMovieContext.SaveChanges();
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AddMovie([FromBody] NewMovie newMovie)
        {
            Movie movie_to_add = new Movie()
            {
                ID = _context.Movie.Count() + 1, Title = newMovie.Title, Genre = newMovie.Genre
            };

            Console.WriteLine(movie_to_add.ID);
            await Task.Delay(5000);

            _context.Movie.Add(movie_to_add);
            _context.SaveChanges();
            return(Ok());
        }
Exemplo n.º 6
0
 public static void PopulateTestData(MvcMovieContext dbContext)
 {
     dbContext.Movie.Add(new Movie()
     {
         Title = "Shrek"
     }
                         );
     dbContext.Movie.Add(new Movie()
     {
         Title = "Shark"
     }
                         );
     dbContext.SaveChanges();
 }
Exemplo n.º 7
0
 public static void Initialize(IServiceProvider serviceProvider)
 {
     using var context = new MvcMovieContext(
               serviceProvider.GetRequiredService <DbContextOptions <MvcMovieContext> >());
     // Look for any movies.
     if (context.Movie.Any())
     {
         return; // DB has been seeded
     }
     context.Movie.AddRange(
         new Movie
     {
         Title       = "FILM1",
         ReleaseDate = DateTime.Parse("2023-12-21"),
         Genre       = "Some shit",
         Price       = 7.23M,
         Country     = "Polska",
         Lenght      = 2
     },
         new Movie
     {
         Title       = "Ghostbusters ",
         ReleaseDate = DateTime.Parse("1984-3-13"),
         Genre       = "Comedy",
         Price       = 8.99M,
         Country     = "Niemcy",
         Lenght      = 1
     },
         new Movie
     {
         Title       = "Ghostbusters 2",
         ReleaseDate = DateTime.Parse("1986-2-23"),
         Genre       = "Comedy",
         Price       = 9.99M,
         Country     = "Hiszpania",
         Lenght      = 1
     },
         new Movie
     {
         Title       = "Rio Bravo",
         ReleaseDate = DateTime.Parse("1959-4-15"),
         Genre       = "Western",
         Price       = 3.99M,
         Country     = "Czechy",
         Lenght      = 1
     }
         );
     context.SaveChanges();
 }
Exemplo n.º 8
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMovieContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcMovieContext> >()))
            {
                // Look for any movies.
                if (context.Movie.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movie.AddRange(
                    new Movie
                {
                    Title       = "Lord Of The Rings Part 1",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Fantasy",
                    Price       = 7.99M
                },

                    new Movie
                {
                    Title       = "Melhor programador de c# do mundo ",
                    ReleaseDate = DateTime.Parse("1984-3-13"),
                    Genre       = "Comedy",
                    Price       = 8.99M
                },

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

                    new Movie
                {
                    Title       = "Filme 2",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Price       = 3.99M
                }
                    );
                context.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public static void Initialize(MvcMovieContext context)
        {
            // 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",
                Rating      = "R",
                Price       = 7.99M
            },

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

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

                new Movie
            {
                Title       = "Rio Bravo",
                ReleaseDate = DateTime.Parse("1959-4-15"),
                Genre       = "Western",
                Rating      = "A",
                Price       = 3.99M
            }
                );
            context.SaveChanges();
        }
        public void Test1()
        {
            MvcMovieContext context = DbAccess.getSqlServerDbContext();

            context.Movie.Add(new Movie {
                Genre = "Classic", Title = "Redemption", Price = 10.05M, ReleaseDate = new DateTime(2001, 1, 18)
            });
            context.Movie.Add(new Movie {
                Genre = "Classic", Title = "Shark", Price = 15.05M, ReleaseDate = new DateTime(2005, 5, 23)
            });
            context.SaveChanges();

            MoviesController controller = new MoviesController(context);

            Assert.True(controller.MovieExists(1));
            Assert.True(controller.MovieExists(2));
            Assert.False(controller.MovieExists(10));
        }
Exemplo n.º 11
0
 public async Task <IActionResult> Create([Bind("ID,Title,ReleaseDate,Genre,Price,Rating")] Movie movie)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _context.Movie.Add(movie);
             _context.SaveChanges();
             return(RedirectToAction(nameof(Index)));
         }
         catch (Exception ex)
         {
             var e = ex;
             throw;
         }
     }
     return(View(movie));
 }
Exemplo n.º 12
0
        public void CreateOrder(Order order)
        {
            order.OrderPlaced = DateTime.Now;
            _mvcMovieContext.Orders.Add(order);

            var shoppingCartItems = _shoppingCart.ShoppingCartItems;

            foreach (var item in shoppingCartItems)
            {
                var orderDetail = new OrderDetail()
                {
                    OrderId = order.OrderId,
                    MovieId = item.Movie.Id,
                    Price   = item.Movie.Price,
                };

                _mvcMovieContext.OrderDetails.Add(orderDetail);
            }
            _mvcMovieContext.SaveChanges();
        }
Exemplo n.º 13
0
        public static void PopulateTestData(MvcMovieContext dbContext)
        {
            // remove everything
            //dbContext.Movie.Remove(new Movie { Id = 1 });
            //dbContext.Movie.Remove(new Movie { Id = 2 });
            //dbContext.Movie.Remove(new Movie { Id = 3 });

            // add movies to "Movie" table
            dbContext.Movie.Add(new Movie {
                Genre = "Classic", Title = "Shawshank Redemption", Price = 10.05M, ReleaseDate = new DateTime(2001, 1, 18)
            });
            dbContext.Movie.Add(new Movie {
                Genre = "Thriller", Title = "Shark", Price = 15.05M, ReleaseDate = new DateTime(2005, 5, 23)
            });
            dbContext.Movie.Add(new Movie {
                Genre = "Kids", Title = "IceAge", Price = 56.34M, ReleaseDate = new DateTime(2001, 6, 6)
            });

            dbContext.SaveChanges();
        }
Exemplo n.º 14
0
        // Create MovieContext with seed data
        private void GetContextWithData()
        {
            var options = new DbContextOptionsBuilder <MvcMovieContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            movieContext = new MvcMovieContext(options);

            var movie1 = new Movie {
                Id = 1, Genre = "Classic", Title = "Redemption"
            };
            var movie2 = new Movie {
                Id = 2, Title = "Avatar", Genre = "Cartoon"
            };

            movieContext.Movie.Add(movie1);
            movieContext.Movie.Add(movie2);
            movieContext.SaveChanges();

            Console.WriteLine("inside movieExistsTest GetContextWithData");
        }
Exemplo n.º 15
0
        public void InsertMovie_in_Memory_Test()
        {
            var options = new DbContextOptionsBuilder <MvcMovieContext>()
                          .UseInMemoryDatabase(databaseName: $"InsertTest{DateTime.Now}")
                          .Options;

            using (var context = new MvcMovieContext(options))
            {
                context.Movie.Add(new Movie {
                    ID = 7, Title = "7", Price = 50M, Genre = "Romance", Rating = "G", ReleaseDate = DateTime.Now
                });
                context.Movie.Add(new Movie {
                    ID = 8, Title = "8", Price = 60M, Genre = "Romance", Rating = "G", ReleaseDate = DateTime.Now
                });
                /// Adding to db
                context.SaveChanges();
            };

            using (var context = new MvcMovieContext(options))
            {
                Assert.Equal(2, context.Movie.ToList().Count);
            }
        }
Exemplo n.º 16
0
        public void FindMovies()
        {
            var options = new DbContextOptionsBuilder <MvcMovieContext>()
                          .UseInMemoryDatabase(databaseName: $"Find{DateTime.Now}")
                          .Options;

            using (var context = new MvcMovieContext(options))
            {
                foreach (var mov in MovieList)
                {
                    context.Movie.Add(mov);
                    context.SaveChanges();
                }
            };

            using (var context = new MvcMovieContext(options))
            {
                var movService = new MovieService(context);
                var result     = movService.FindByTitle("1");

                Assert.Equal(2, result.Count());
            }
        }
Exemplo n.º 17
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMovieContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcMovieContext> >()))
            {
                if (context.Movie.Any())
                {
                    return;
                }

                context.Movie.AddRange(
                    new Movie
                {
                    Title       = "test",
                    ReleaseDate = DateTime.Parse("2013-1-1"),
                    Genre       = "Horror",
                    Rating      = "7",
                    Price       = 1M
                }
                    );
                context.SaveChanges();
            }
        }
Exemplo n.º 18
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMovieContext(
                       serviceProvider.GetRequiredService <DbContextOptions <MvcMovieContext> >()))
            {
                if (context.Movie.Any())
                {
                    return; //DB has been seeded
                }

                context.Movie.AddRange(
                    new Movie
                {
                    Title       = "Iron Man",
                    ReleaseDate = DateTime.Parse("2008-5-2"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "The Incredible Hulk",
                    ReleaseDate = DateTime.Parse("2008-6-13"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Iron Man 2",
                    ReleaseDate = DateTime.Parse("2010-5-7"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Thor",
                    ReleaseDate = DateTime.Parse("2011-5-6"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Captain America: The First Avenger",
                    ReleaseDate = DateTime.Parse("2011-7-22"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Marvel's The Avengers",
                    ReleaseDate = DateTime.Parse("2012-5-4"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Iron Man 3",
                    ReleaseDate = DateTime.Parse("2013-5-13"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Thor: The Dark World",
                    ReleaseDate = DateTime.Parse("2013-11-8"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Captain America: The Winter Soldier",
                    ReleaseDate = DateTime.Parse("2014-4-4"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Guardians of the Galaxy",
                    ReleaseDate = DateTime.Parse("2014-8-1"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Avengers: Age of Ultron",
                    ReleaseDate = DateTime.Parse("2015-5-1"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Ant-Man",
                    ReleaseDate = DateTime.Parse("2015-7-15"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Captain America: Civil War",
                    ReleaseDate = DateTime.Parse("2016-5-6"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Doctor Strange",
                    ReleaseDate = DateTime.Parse("2016-11-4"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Guardians of the Galaxy Vol. 2",
                    ReleaseDate = DateTime.Parse("2017-5-5"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Spider-Man: Homecoming",
                    ReleaseDate = DateTime.Parse("2017-7-7"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Thor: Ragnarok",
                    ReleaseDate = DateTime.Parse("2017-11-3"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Black Panther",
                    ReleaseDate = DateTime.Parse("2018-2-16"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Avengers: Infinity War",
                    ReleaseDate = DateTime.Parse("2018-4-27"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Ant-Man and the Wasp",
                    ReleaseDate = DateTime.Parse("2018-7-6"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Captain Marvel",
                    ReleaseDate = DateTime.Parse("2019-3-8"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Avengers: Endgame",
                    ReleaseDate = DateTime.Parse("2019-4-26"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Spider-Man: Far from Home",
                    ReleaseDate = DateTime.Parse("2019-7-2"),
                    Genre       = "Action",
                    Rating      = "PG-13",
                    Price       = 9.99M
                }
                    );

                context.SaveChanges();
            }
        }
 public void Add(Movie model)
 {
     _db.Movie.Add(model);
     _db.SaveChanges();
 }
Exemplo n.º 20
0
        public async void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMovieContext(serviceProvider.GetRequiredService <DbContextOptions <MvcMovieContext> >()))
            {
                // Look for any movies.

                /*
                 * if (context.Movie.Any())
                 * {
                 *  return;   // DB has been seeded
                 * }
                 */
                if (context.Movie.Any())
                {
                    return;   // DB has been seeded
                }

                themoviedbResponse data = await GetDataTaskAsync();

                foreach (Movie movie in data.results)
                {
                    Console.Write(movie.title);
                    if (context.Movie.Any(db => db.id == movie.id))
                    {
                        continue;
                    }
                    context.Movie.AddRange(movie);
                }

                // context.Movie.AddRange(
                //      new Movie
                //      {
                //          Title = "When Harry Met Sally",
                //          ReleaseDate = DateTime.Parse("1989-1-11"),
                //          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();
            }
        }
Exemplo n.º 21
0
 public void Create(Watchlist watchlist)
 {
     _context.Watchlist.Add(watchlist);
     _context.SaveChanges();
 }
Exemplo n.º 22
0
        public ActionResult setPath(int x, int y)
        {
            Console.WriteLine("Set path, X: " + x + " Y: " + y);

            List <Location> testL = new List <Location>();

            int act = 0;

            foreach (var l in _context.Location)
            {
                testL.Add(l);
            }

            List <Location> updatedTestL = new List <Location>();
            LocationGroup   lg           = new LocationGroup {
                locations = testL
            };
            Grid model = new Grid {
                action = 0, cId = 0, grid = lg
            };

            var a = _context.G;

            foreach (var ac in a)
            {
                if (x == 100 && y == 100)
                {
                    ac.action = 1;
                }
                else if (x == 101 && y == 101)
                {
                    ac.action = 2;
                }
                else if (x == 102 && y == 102)
                {
                    ac.action = 3;
                }
                else if (x == 103 && y == 103)
                {
                    ac.action = 0;
                }
                else if (x == 104 && y == 104)
                {
                    AStar findPath = new AStar(testL);
                    Console.WriteLine("CHECK B");
                    updatedTestL = findPath.findPath();
                    Console.WriteLine("CHECK G");
                }
                _context.SaveChanges();
                act = ac.action;
            }


            if (x != 104)
            {
                Location rip = new Location {
                    XLoc = 0, YLoc = 0, myD = 0
                };

                foreach (var l in model.grid.locations)
                {
                    if (l.XLoc == x && l.YLoc == y)
                    {
                        rip = new Location {
                            XLoc = l.XLoc, YLoc = l.YLoc, myD = act
                        };
                        l.myD = act;
                        _context.SaveChanges();
                        updatedTestL.Add(rip);
                    }
                    else
                    {
                        updatedTestL.Add(l);
                    }
                }
            }

            model.grid.locations = updatedTestL;
            return(View("Index", model));
        }
Exemplo n.º 23
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMovieContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcMovieContext> >()))
            {
                // Look for movies ->

                if (context.Movie.Any())
                {
                    return;  //DB is seeded...
                }

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

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

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

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

                    new Movie
                {
                    Title       = "Kill Bill",
                    ReleaseDate = DateTime.Parse("2003-10-16"),
                    Genre       = "Action",
                    Price       = 8.9m
                },

                    new Movie
                {
                    Title       = "Prometheus",
                    ReleaseDate = DateTime.Parse("2012-7-6"),
                    Genre       = "Sci-Fi",
                    Price       = 8.99m
                },

                    new Movie
                {
                    Title       = "Dr. No",
                    ReleaseDate = DateTime.Parse("1963-7-4"),
                    Genre       = "Action",
                    Price       = 9.99m
                }



                    );


                context.SaveChanges();
            }
        }
 public void Save()
 {
     _context.SaveChanges();
 }
Exemplo n.º 25
0
        public async Task <IActionResult> SeedDatabase()
        {
            try
            {
                string[] cities = { "Avery",    "Boston",  "Canadaigua", "Dalton",   "Eastwood", "Franck", "Gopherville", "Handley", "Interlachen", "Joesephine", "Kazaam",
                                    "Lincoln",  "Manners", "Nopline",    "Oscaloa",  "Pinsal",
                                    "Quantine", "Rufus",   "Seldom",     "Tankeral", "Uranium",
                                    "Vesper",   "Walden",  "Vandolf",    "Xuxa",     "Yolo",     "Zingping" };

                string[] firstNames = { "Action", "AAA",   "Bing",
                                        "Cash",   "Cheap", "Elite","Best",
                                        "Great",  "Good",  "First","Fresh" };

                string[] lastNames = { "Video", "Entertainment", "Vids", "Video Rentals", "Home Cinema", "DvD", "Movies", "Movie Rentals", "Zinema", "Flicks" };

                string[] movies1 = { "A new", "Best", "Candid", "Cute", "Dangerous", "Brightest", "Daring", "My Darling", "First",
                                     "Fresh" };

                string[] movies2 = { "Alligator", "Alley", "Kitty", "Puppy", " Barbeque Grill", "Night Watchman", "Meter Patrol", " Desert Land", "Castaways", "Pastry Chef" };



                //Ensure that we have basic sample data in database
                bool created = await _context.Database.EnsureCreatedAsync();

                var firstSeller = (from s in _context.Sellers
                                   where s.Id == 1
                                   select s).FirstOrDefault();

                const int SELLERCOUNT = 20;
                const int MOVIECOUNT  = 30;

                int j;
                if (firstSeller == null)
                {
                    j = 1;
                    for (int i = 1; i <= SELLERCOUNT; i++)
                    {
                        string name = firstNames[i % 10] + " " + lastNames[j];
                        _context.Sellers.Add(new Seller()
                        {
                            Address1 = string.Format("{0} {1} Street", i, firstNames[i % 10]),
                            City     = cities[i % 10],
                            State    = "MA",
                            Name     = name,
                            Phone    = (5551212 + i).ToString(),
                            URL      = "http://localhost/sellers/detail/" + i.ToString(),
                            Zip      = (10000 + i).ToString()
                        });
                        if (i % 10 == 0)
                        {
                            j += 1;
                        }
                    }



                    j = 1;
                    //movies
                    for (int i = 1; i <= MOVIECOUNT; i++)
                    {
                        string name = $"{movies1[i % 10]} {movies2[i % j]}";
                        _context.Movie.Add(new Movie()
                        {
                            Genre       = "Western",
                            Price       = (decimal)(10.00 + ((double)i * .40)),
                            ReleaseDate = new DateTime(2020 - i, i % 11 + 1, i % 27 + 1),
                            Title       = name
                        });

                        if (i % 10 == 0)
                        {
                            j += 1;
                        }
                    }

                    _context.SaveChanges();

                    int lastMovie  = _context.Movie.OrderBy(t => t.Id).Last().Id;
                    int lastSeller = _context.Sellers.OrderBy(s => s.Id).Last().Id;


                    var rnd = new System.Random(23);


                    //movie price
                    for (int i = 0; i < 20; i++)
                    {
                        _context.MoviePrices.Add(new MoviePrice()
                        {
                            DateEntered = new DateTime((int)(50 * rnd.NextDouble() + 1970), (int)(11 * rnd.NextDouble() + 1), (int)(27 * rnd.NextDouble() + 1)),

                            MovieId  = (int)(lastMovie - rnd.Next(MOVIECOUNT)),
                            SellerId = (int)(lastSeller - rnd.Next(SELLERCOUNT)),
                            Price    = rnd.NextDouble() * 50
                        });
                    }
                    _context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
            }

            return(View());
        }
        public async Task <IActionResult> Post(List <IFormFile> files)
        {
            int tmpltId = 0;

            if (!string.IsNullOrWhiteSpace(Request.Form["tmpltId"]))
            {
                int.TryParse(Request.Form["tmpltId"], out tmpltId);
            }

            var Templates = new Dictionary <string, string>()
            {
                { "Zombie", "2187" },
            };

            long size = files.Sum(f => f.Length);

            // full path to file in temp location


            if (1 == files.Count)
            {
                var formFile = files[0];

                var filePath = Path.GetTempFileName() + Path.GetExtension(formFile.FileName);


                if (formFile.Length > 0)
                {
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await formFile.CopyToAsync(stream);
                    }
                }

                string uploadedImageUrl;

                using (var uploadImageWebClient = new WebClient())
                {
                    byte[] responseArray = uploadImageWebClient.UploadFile(c_api_upload_endpoint, filePath);

                    uploadedImageUrl = Encoding.UTF8.GetString(responseArray);
                }

                string transformedImageUrl;

                using (var httpClient = new HttpClient())
                {
                    var values = new Dictionary <string, string>
                    {
                        { "image_url[1]", uploadedImageUrl },
                        { "template_name", Templates.ToList()[tmpltId].Value }
                    };

                    var content = new FormUrlEncodedContent(values);

                    var response = await httpClient.PostAsync(c_api_photolab_tmplt_endpoint, content);

                    transformedImageUrl = await response.Content.ReadAsStringAsync();
                }

                string bluredImageUrl;

                using (var httpClient = new HttpClient())
                {
                    var values = new Dictionary <string, string>
                    {
                        { "image_url[1]", transformedImageUrl },
                        //{ "template_name", "DD406536-1D2F-B0D4-7D0F-51828625B52D" /* blur1 */ }
                        { "template_name", "BC75E995-B4CF-7854-E165-C734EEC2A775" /* blur2 */ }
                    };

                    var content = new FormUrlEncodedContent(values);

                    var response = await httpClient.PostAsync(c_api_custom_tmplt_endpoint, content);

                    bluredImageUrl = await response.Content.ReadAsStringAsync();
                }


                Muck muck = new Muck
                {
                    AppliedTemplate   = Templates.ToList()[tmpltId].Key,
                    AuthorEmail       = User.Identity.Name,
                    UploadedImageURL  = uploadedImageUrl,
                    ConvertedImageURL = transformedImageUrl,
                    BluredImageURL    = bluredImageUrl,
                    Image             = System.IO.File.ReadAllBytes(filePath)
                };

                {
                    _context.Muck.Add(muck);

                    _context.SaveChanges();
                }


                return(RedirectToAction("Details", "Mucks", new { id = muck.Id }));

                //Response.Redirect("~/Mucks/Details/" + muck.Id,);

                //return Ok(new { count = files.Count, size, filePath, uploadedImageUrl, transformedImageUrl, bluredImageUrl, insertedId = muck.Id });
            }
            else
            {
                return(Ok(new { count = 0 }));
            }
            // process uploaded files
            // Don't rely on or trust the FileName property without validation.
        }
Exemplo n.º 27
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMovieContext(serviceProvider.GetRequiredService <DbContextOptions <MvcMovieContext> >()))
            {
                // 存在するか
                if (context.Movie.Any())
                {
                    return;
                }

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

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

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

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

                    );

/*
 *              for (int i = 0; i < 10000; i++)
 *              {
 *                  context.Movie.Add(new Movie {
 *                      Title = $"TEST{i}",
 *                      ReleaseDate = DateTime.Parse("1959-4-15"),
 *                      Genre = "Western",
 *                      Rating = "R",
 *                      Price = 3.99M
 *                  });
 *              }
 */
                context.SaveChanges();
            }
        }
Exemplo n.º 28
0
 public IActionResult Display(Movie movie)
 {
     _db.Movie.Update(movie);
     _db.SaveChanges();
     return(View(movie));
 }
Exemplo n.º 29
0
 void IMovieService.Create(Movie movie)
 {
     _context.Movie.Add(movie);
     _context.SaveChanges();
 }
Exemplo n.º 30
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcMovieContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcMovieContext> >()))
            {
                // Look for any movies.
                if (context.Movie.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movie.AddRange(
                    new Movie
                {
                    Title       = "Terminator 1",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Price       = 7.99M,
                    Producer    = "Producer 1"
                },

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

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

                    new Movie
                {
                    Title       = "Terminator 4",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Price       = 3.99M,
                    Producer    = "Producer 4"
                },
                    new Movie
                {
                    Title       = "Terminator 5",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Price       = 7.99M,
                    Producer    = "Producer 5"
                },

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

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

                    new Movie
                {
                    Title       = "Terminator 8",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Price       = 3.99M,
                    Producer    = "Producer 9"
                },
                    new Movie
                {
                    Title       = "Terminator 9",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Price       = 7.99M,
                    Producer    = "Producer 9"
                },

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

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

                    new Movie
                {
                    Title       = "Terminator 13",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Price       = 3.99M,
                    Producer    = "Producer 13"
                },
                    new Movie
                {
                    Title       = "Terminator 14",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Price       = 7.99M,
                    Producer    = "Producer 14"
                },

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

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

                    new Movie
                {
                    Title       = "Terminator 17",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Price       = 3.99M,
                    Producer    = "Producer 17"
                }
                    );
                context.SaveChanges();
            }
        }