Exemplo n.º 1
0
        public async Task SeedAsync(ExamContext context, ILogger <ExamContextSeed> logger, int retries = 3)
        {
            var policy = CreatePolicy(retries, logger, nameof(ExamContextSeed));

            await policy.ExecuteAsync(async() =>
            {
                if (!context.Users.Any())
                {
                    await context.Users.AddAsync(
                        GetAdminUser());

                    await context.SaveChangesAsync();
                }
            });
        }
Exemplo n.º 2
0
        public static void Initialize(ExamContext context)
        {
            //context.Database.EnsureCreated();
            context.Database.AutoTransactionsEnabled = true;
            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }
            if (!context.Users.Any())
            {
                context.Users.Add(GetAdminUser());


                context.SaveChanges();
            }
        }