示例#1
0
        private static async Task InitProductLine(ESShopContext context)
        {
            var firstProduct = await context.Products.FirstOrDefaultAsync();

            var firstOrder = await context.Orders.FirstOrDefaultAsync();

            if (!context.ProductLines.Any())
            {
                var productLineList = new List <ProductLine>()
                {
                    new()
                    {
                        Product  = firstProduct,
                        Quantity = 10,
                        Order    = firstOrder
                    },
                    new()
                    {
                        Product  = firstProduct,
                        Quantity = 2,
                        Order    = firstOrder
                    }
                };

                context.ProductLines.AddRange(productLineList);
                await context.SaveChangesAsync();
            }
        }
示例#2
0
        private static async Task InitOrder(ESShopContext context)
        {
            if (!context.Orders.Any())
            {
                var order = new Order()
                {
                    DeliverAddress = "Test address",
                    IsDelivered    = false,
                    TotalPrice     = 1400d
                };

                context.Orders.Add(order);
                await context.SaveChangesAsync();
            }
        }
示例#3
0
        private static async Task InitProduct(ESShopContext context)
        {
            if (!context.Products.Any())
            {
                var productList = new List <Product>()
                {
                    new ()
                    {
                        Name  = "Product 1",
                        Price = 45d
                    },
                    new ()
                    {
                        Name  = "Product 2",
                        Price = 25d
                    }
                };

                context.Products.AddRange(productList);
                await context.SaveChangesAsync();
            }
        }
    }