Example #1
0
        public async Task SeedAsync()
        {
            await _context.Database.MigrateAsync().ConfigureAwait(false);

            if (!await _context.ProductCategories.AnyAsync())
            {
                _logger.LogInformation("Seeding initial data");

                ProductCategory prodCat_1 = new ProductCategory
                {
                    Name        = "None",
                    Description = "Default category. Products that have not been assigned a category",
                    CreatedDate = DateTime.UtcNow,
                    UpdatedDate = DateTime.UtcNow
                };

                Product prod_1 = new Product
                {
                    Name            = "BMW M6",
                    Description     = "Yet another masterpiece from the world's best car manufacturer",
                    BuyingPrice     = 109775,
                    SellingPrice    = 114234,
                    UnitsInStock    = 12,
                    IsActive        = true,
                    ProductCategory = prodCat_1,
                    CreatedDate     = DateTime.UtcNow,
                    UpdatedDate     = DateTime.UtcNow
                };

                Product prod_2 = new Product
                {
                    Name            = "Nissan Patrol",
                    Description     = "A true man's choice",
                    BuyingPrice     = 78990,
                    SellingPrice    = 86990,
                    UnitsInStock    = 4,
                    IsActive        = true,
                    ProductCategory = prodCat_1,
                    CreatedDate     = DateTime.UtcNow,
                    UpdatedDate     = DateTime.UtcNow
                };

                _context.Products.Add(prod_1);
                _context.Products.Add(prod_2);

                await _context.SaveChangesAsync();

                _logger.LogInformation("Seeding initial data completed");
            }
        }
Example #2
0
 public async Task <bool> CommitAsync()
 {
     return(await _DbContext.SaveChangesAsync() > 0);
 }