コード例 #1
0
        public static async Task SeedAsync(DikolDbContext dikolDbContext)
        {
            #region Code smell

            if (!dikolDbContext.ProductTypes.Any())
            {
                var productTypesData = File.ReadAllText("../Dikol.Infrastructure/DbSeeder/Data/product-types.json");

                var productTypes = JsonSerializer.Deserialize <List <ProductType> >(productTypesData);

                foreach (var productType in productTypes)
                {
                    dikolDbContext.ProductTypes.Add(productType);
                }
            }

            // TODO: Make it generic
            if (!dikolDbContext.ProductBrands.Any())
            {
                var brandsData = File.ReadAllText("../Dikol.Infrastructure/DbSeeder/Data/product-brands.json");

                var brands = JsonSerializer.Deserialize <List <ProductBrand> >(brandsData);

                foreach (var brand in brands)
                {
                    dikolDbContext.ProductBrands.Add(brand);
                }
            }

            if (!dikolDbContext.Products.Any())
            {
                var productsData = File.ReadAllText("../Dikol.Infrastructure/DbSeeder/Data/products.json");

                var products = JsonSerializer.Deserialize <List <Product> >(productsData);

                foreach (var product in products)
                {
                    dikolDbContext.Products.Add(product);
                }
            }

            await dikolDbContext.SaveChangesAsync();

            #endregion
        }
コード例 #2
0
 public BuggyController(DikolDbContext dikolDbContext)
 {
     _dikolDbContext = dikolDbContext;
 }
コード例 #3
0
ファイル: GenericRepository.cs プロジェクト: Bohdannn/Dikol
 public GenericRepository(DikolDbContext dikolDbContext)
 {
     _dikolDbContext = dikolDbContext;
 }