public static async Task Initialize( DataProtectionKeysContext dataProtectionKeysContext, ApplicationDbContext applicationDbContext, IFunctionalSvc functionalSvc, ICountrySvc countrySvc ) { // Check, if db DatProtectionKeysContext is created // Check, if db ApplicationDbContext is created await dataProtectionKeysContext.Database.EnsureCreatedAsync(); await applicationDbContext.Database.EnsureCreatedAsync(); // Check, if db contains any users. If db is not empty, then db has been already seeded if (applicationDbContext.ApplicationUsers.Any()) { return; } // If empty create Admin User and App User await functionalSvc.CreateDefaultAdminUser(); await functionalSvc.CreateDefaultUser(); // Populate Country database var countries = await countrySvc.GetCountriesAsync(); if (countries.Count > 0) { await applicationDbContext.Countries.AddRangeAsync(countries); await applicationDbContext.SaveChangesAsync(); } }
public static async Task Initialize( DataProtectionKeysContext dataProtectionKeysContext, ApplicationDbContext applicationDbContext, IFunctionalSvc functionalSvc, ICountrySvc countrySvc) { await dataProtectionKeysContext.Database.EnsureCreatedAsync(); await applicationDbContext.Database.EnsureCreatedAsync(); if (applicationDbContext.ApplicationUsers.Any()) { return; } // If empty create Admin User and App User await functionalSvc.CreateDefaultAdminUser(); await functionalSvc.CreateDefaultUser(); // Populate Country database var countries = await countrySvc.GetCountriesAsync(); if (countries.Count > 0) { await applicationDbContext.Countries.AddRangeAsync(countries); await applicationDbContext.SaveChangesAsync(); } }
public static async Task Initializer(ApplicationDbContext context, DataProtectionContext dpContext, ICommonFunction icommonFunction, ICountrySvc _countrySvc) { //check whether database exists if (!(context.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists()) { await context.Database.EnsureCreatedAsync(); } if (!(dpContext.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists()) { await dpContext.Database.EnsureCreatedAsync(); } //await dpContext.Database.MigrateAsync(); if (context.appUsers.Any()) { return; } //if (context.appUsers != null) { return; } await icommonFunction.CreateAdminUser(); await icommonFunction.CreateAppUser(); //Initialize the coutry datatbase table var countries = await _countrySvc.GetCountries(); if (countries.Count > 0) { await context.countries.AddRangeAsync(countries); await context.SaveChangesAsync(); } }