Exemple #1
0
        public void UpsertProduct(ProductToGet product)
        {
            var p = _context.Products.Find(product.ProductId);

            if (p == null)
            {
                p = new Product();
                _context.Products.Add(p);

                p.ProductId = product.ProductId;
                p.StoreId   = _configuration.GetSection("Store:Id").Get <Guid>();
            }

            p.Image = product.Image;
            p.Name  = product.Name;
            p.Price = product.Price;

            p.Ingredients.Clear();
            foreach (var item in product.Items)
            {
                p.Ingredients.Add(new Item {
                    ItemId = item.ItemId, Name = item.Name
                });
            }

            _context.SaveChanges();
        }
        public static void Seed(this StoreCatalogContext context)
        {
            var productsTxt = File.ReadAllText("products.json");
            var products    = JsonConvert.DeserializeObject <List <Product> >(productsTxt);

            context.Products.AddRange(products);

            context.SaveChanges();
        }