Esempio n. 1
0
        public static async Task SeedAsync(TimewasterDbContext context,
                                           ILoggerFactory loggerFactory, int?retry = 0)
        {
            int retryForAvailability = retry.Value;

            try
            {
                if (!await context.Statuses.AnyAsync())
                {
                    await context.Statuses.AddRangeAsync(GetDefaultStatuses());

                    await context.SaveChangesAsync();
                }
#if DEBUG
                if (!await context.Projects.AnyAsync())
                {
                    await context.Projects.AddRangeAsync(GetProjects());

                    await context.SaveChangesAsync();
                }

                if (!await context.Sprints.AnyAsync())
                {
                    await context.Sprints.AddRangeAsync(GetSprints());

                    await context.SaveChangesAsync();
                }
#endif
            }
            catch (Exception e)
            {
                if (retryForAvailability < 10)
                {
                    retryForAvailability++;
                    var log = loggerFactory.CreateLogger <TimewasterDbContext>();
                    log.LogError(e.Message);
                    await SeedAsync(context, loggerFactory, retryForAvailability);
                }
                throw;
            }
        }
Esempio n. 2
0
 public AsyncRepository(TimewasterDbContext context) => _context = context;