public static void Seed(ProductsContext productContext)
        {
            if (!productContext.Products.Any())
            {
                var products = new List <Product>
                {
                    new Product
                    {
                        CreatedTime = DateTime.UtcNow,
                        Description = "DEsc",
                        Name        = "Name",
                        Price       = 799,
                        Status      = ProductStatus.INSTOCK
                    }
                };

                productContext.Products.AddRange(products);
                productContext.SaveChanges();
            }
        }
Esempio n. 2
0
 public static void SeedAsync(ProductsContext productsContext)
 {
     if (!productsContext.Product.Any())
     {
         var products = new List <Product>
         {
             new Product
             {
                 ProductId   = 1,
                 Name        = "Mi10T",
                 Description = "New Xiaomi Phone Mi10T",
                 Price       = 699,
                 Status      = ProductStatus.INSTOCK,
                 CreatedTime = DateTime.UtcNow
             },
             new Product
             {
                 ProductId   = 2,
                 Name        = "P40",
                 Description = "New Huawei Phone P40",
                 Price       = 899,
                 Status      = ProductStatus.INSTOCK,
                 CreatedTime = DateTime.UtcNow
             },
             new Product
             {
                 ProductId   = 3,
                 Name        = "A50",
                 Description = "New Samsung Phone A50",
                 Price       = 399,
                 Status      = ProductStatus.INSTOCK,
                 CreatedTime = DateTime.UtcNow
             }
         };
         productsContext.Product.AddRange(products);
         productsContext.SaveChanges();
     }
 }