public static async Task SeedAsync(NotifyContext notifyContext, ILoggerFactory loggerFactory, int?retry = 0) { int retryForAvailability = retry.Value; try { //if (!notifyContext.Phones.Any()) //{ // notifyContext.Phones.AddRange(GetPreconfiguredPhones()); // await notifyContext.SaveChangesAsync(); //} if (!notifyContext.FireDepartments.Any()) { notifyContext.FireDepartments.AddRange(GetPreconfiguredFireDepartments()); await notifyContext.SaveChangesAsync(); } if (!notifyContext.FireFighters.Any()) { notifyContext.FireFighters.AddRange(GetPreconfiguredFireFighters()); await notifyContext.SaveChangesAsync(); } } catch (Exception ex) { if (retryForAvailability < 10) { retryForAvailability++; var log = loggerFactory.CreateLogger <NotifyContextSeed>(); log.LogError(ex.Message); await SeedAsync(notifyContext, loggerFactory, retryForAvailability); } throw; } }
public EfRepository(NotifyContext dbContext) { _dbContext = dbContext; }