Esempio n. 1
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            StoreDBContext context = app.ApplicationServices
                                     .CreateScope().ServiceProvider.GetRequiredService <StoreDBContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }
            if (!context.Products.Any())
            {
                context.Products.AddRange
                (
                    new Product
                {
                    ProductName  = "Rumi Doughnut",
                    ProductDesc  = "Fills you up slightly, gives lots of energy!",
                    ProductPrice = 2.00m,
                    Category     = "Consumables"
                },
                    new Product
                {
                    ProductName  = "Rumi Cake",
                    ProductDesc  = "Fills you up completely! Very sweet.",
                    ProductPrice = 10.00m,
                    Category     = "Consumables"
                },
                    new Product
                {
                    ProductName  = "Carrot",
                    ProductDesc  = "Home grown, freshly harvested.",
                    ProductPrice = 1.00m,
                    Category     = "Consumables"
                },
                    new Product
                {
                    ProductName  = "Bunny Game",
                    ProductDesc  = "This store is a reference to a video game, see if you can find it!",
                    ProductPrice = 2.00m,
                    Category     = "Misc"
                },
                    new Product
                {
                    ProductName  = "Attack Up",
                    ProductDesc  = "Makes you hit harder!",
                    ProductPrice = 50.00m,
                    Category     = "Upgrades"
                },
                    new Product
                {
                    ProductName  = "Health Up",
                    ProductDesc  = "Makes you a bit harder to take out!",
                    ProductPrice = 75.00m,
                    Category     = "Upgrades"
                }
                );
                context.SaveChanges();
            }
        }
Esempio n. 2
0
 public void SaveOrder(Order order)
 {
     context.AttachRange(order.Lines.Select(l => l.Product));
     if (order.OrderID == 0)
     {
         context.Orders.Add(order);
     }
     context.SaveChanges();
 }
Esempio n. 3
0
 public void CreateProduct(Product p)
 {
     context.Add(p);
     context.SaveChanges();
 }