public static async Task SeedProductLinkSubCategoriesAsync(StoreContext context)
        {
            if (!context.productAndSubCategories.Any())
            {
                var productAndSubCategoryData = await File.ReadAllTextAsync("../Services/Seeds/Data/LinkProductAndSubCategory.json");

                var data = JsonSerializer.Deserialize <List <ProductAndSubCategory> >(productAndSubCategoryData);
                foreach (var item in data)
                {
                    var productLinkSubCategory = new ProductAndSubCategory()
                    {
                        ProductId     = item.ProductId,
                        SubCategoryId = item.SubCategoryId
                    };
                    await context.AddAsync(productLinkSubCategory);

                    await context.SaveChangesAsync();
                }
            }
        }
Beispiel #2
0
 public async Task <bool> UpdateSubCategoryWithProduct(ProductAndSubCategory entity)
 {
     _context.Update(entity);
     return(await SaveChanges());
 }
Beispiel #3
0
        public async Task <bool> AddSubCategoryToProduct(ProductAndSubCategory entity)
        {
            await _context.AddAsync(entity);

            return(await SaveChanges());
        }