Example #1
0
        public async Task SeedAsync(int retry = 0)
        {
            try
            {
                dbContext.Database.Migrate();

                if (!await dbContext.Customers.AnyAsync())
                {
                    dbContext.Customers.AddRange(CustomerSeed.GetTestData());
                }

                if (!await dbContext.Countries.AnyAsync())
                {
                    dbContext.Countries.AddRange(CountrySeed.GetTestData());
                }

                if (!await dbContext.Cities.AnyAsync())
                {
                    dbContext.Cities.AddRange(CitySeed.GetTestData());
                }

                await dbContext.SaveChangesAsync();
            }
            catch (Exception)
            {
                if (retry > 0)
                {
                    await SeedAsync(retry - 1);
                }
            }
        }