Beispiel #1
0
        public static async Task SeedAsync(WarehouseContext context,
                                           ILoggerFactory loggerFactory, int?retry = 0)
        {
            int retryForAvailability = retry.Value;

            try
            {
                if (!await context.Products.AnyAsync())
                {
                    await context.Products.AddRangeAsync(
                        GetProducts());

                    await context.SaveChangesAsync();
                }

                if (!await context.WarehouseItems.AnyAsync())
                {
                    await context.WarehouseItems.AddRangeAsync(
                        GetWarehouseItems());

                    await context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                if (retryForAvailability < 10)
                {
                    retryForAvailability++;
                    var log = loggerFactory.CreateLogger <WarehouseContextSeed>();
                    log.LogError(ex.Message);
                    await SeedAsync(context, loggerFactory, retryForAvailability);
                }
                throw;
            }
        }
Beispiel #2
0
 public async Task SaveChangesAsync(CancellationToken cancellationToken = default)
 {
     await _context.SaveChangesAsync(cancellationToken);
 }