Exemplo n.º 1
0
        public static async Task seedAsync(storeContext context, ILoggerFactory loggerFactory)
        {
            try{
                if (!context.ProductBrands.Any())
                {
                    var brandsData = File.ReadAllText("../Infrastructure/Data/SeedData/brands.json");
                    var brands     = JsonSerializer.Deserialize <List <ProductBrand> >(brandsData);

                    foreach (var item in brands)
                    {
                        context.ProductBrands.Add(item);
                    }
                    await context.SaveChangesAsync();
                }

                if (!context.productTypes.Any())
                {
                    var typesData = File.ReadAllText("../Infrastructure/Data/SeedData/types.json");
                    var types     = JsonSerializer.Deserialize <List <ProductType> >(typesData);

                    foreach (var item in types)
                    {
                        context.productTypes.Add(item);
                    }
                    await context.SaveChangesAsync();
                }

                if (!context.products.Any())
                {
                    var productsData = File.ReadAllText("../Infrastructure/Data/SeedData/products.json");
                    var products     = JsonSerializer.Deserialize <List <product> >(productsData);

                    foreach (var item in products)
                    {
                        context.products.Add(item);
                    }
                    await context.SaveChangesAsync();
                }
            }catch (Exception ex) {
                var logger = loggerFactory.CreateLogger <StoreContextSeed>();
                logger.LogError(ex.Message);
            }
        }
Exemplo n.º 2
0
 public GenericRepository(storeContext context)
 {
     _context = context;
 }
Exemplo n.º 3
0
 public ProuductRepository(storeContext context)
 {
     _context = context;
 }