Exemplo n.º 1
0
        public static async Task EnsureSeedDataAsync(RmsDbContext rmsDbContext,
                                                     ILoggerFactory loggerFactory, int?retry = 0)
        {
            int retryForAvailability = retry.Value;

            try
            {
                if (!rmsDbContext.Users.Any())
                {
                    var user = new User()
                    {
                    };
                    rmsDbContext.Add(user);
                    await rmsDbContext.SaveChangesAsync();
                }

                var dataText = System.IO.File.ReadAllText(@"docs\Countries.json");
                if (!rmsDbContext.Countries.Any())
                {
                    var countries = JsonConvert.DeserializeObject(dataText);
                }
            }
            catch (Exception ex)
            {
                if (retryForAvailability < 10)
                {
                    retryForAvailability++;
                    var log = loggerFactory.CreateLogger <RmsDbContextSeedData>();
                    log.LogError(ex.Message);
                    await EnsureSeedDataAsync(rmsDbContext, loggerFactory, retryForAvailability);
                }
            }
        }
Exemplo n.º 2
0
        public static bool AllMigrationsApplied(this RmsDbContext rmsDbContext)
        {
            var applied = rmsDbContext.GetService <IHistoryRepository>().GetAppliedMigrations()
                          .Select(m => m.MigrationId);
            var total = rmsDbContext.GetService <IMigrationsAssembly>().Migrations.Select(m => m.Key);

            return(!total.Except(applied).Any());
        }
Exemplo n.º 3
0
 public EfRepository(RmsDbContext dbContext)
 {
     DbContext = dbContext;
 }
Exemplo n.º 4
0
 public static void EnsureSeeded(this RmsDbContext rmsDbContext)
 {
 }