public void Add(Game game)
        {
            //Determine the next ID
            var newID = _context.BoardGames.Select(x => x.ID).Max() + 1;

            game.ID = newID;

            _context.BoardGames.Add(game);
            _context.SaveChanges();
        }
Exemplo n.º 2
0
        public IActionResult Add(BoardGame game)
        {
            //Determine the next ID
            var newID = _context.BoardGames.Select(x => x.ID).Max() + 1;

            game.ID = newID;

            _context.BoardGames.Add(game);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new BoardGamesDBContext(serviceProvider.GetRequiredService <DbContextOptions <BoardGamesDBContext> >()))
            {
                // Look for any board games already in database.
                if (context.BoardGames.Any())
                {
                    return;   // Database has been seeded
                }

                context.BoardGames.AddRange(
                    new BoardGame
                {
                    ID                = 1,
                    Title             = "Candy Land",
                    PublishingCompany = "Hasbro",
                    MinPlayers        = 2,
                    MaxPlayers        = 4
                },
                    new BoardGame
                {
                    ID                = 2,
                    Title             = "Sorry!",
                    PublishingCompany = "Hasbro",
                    MinPlayers        = 2,
                    MaxPlayers        = 4
                },
                    new BoardGame
                {
                    ID                = 3,
                    Title             = "Ticket to Ride",
                    PublishingCompany = "Days of Wonder",
                    MinPlayers        = 2,
                    MaxPlayers        = 5
                },
                    new BoardGame
                {
                    ID                = 4,
                    Title             = "The Settlers of Catan (Expanded)",
                    PublishingCompany = "Catan Studio",
                    MinPlayers        = 2,
                    MaxPlayers        = 6
                },
                    new BoardGame
                {
                    ID                = 5,
                    Title             = "Carcasonne",
                    PublishingCompany = "Z-Man Games",
                    MinPlayers        = 2,
                    MaxPlayers        = 5
                },
                    new BoardGame
                {
                    ID                = 6,
                    Title             = "Sequence",
                    PublishingCompany = "Jax Games",
                    MinPlayers        = 2,
                    MaxPlayers        = 6
                });

                context.SaveChanges();
            }
        }