public static void InitializeUsersRolesDb(UsersRolesDB context) { context.Database.EnsureCreated(); if (!context.UserRoles.Any()) { SeedUsersRolesDB.GenerateSeed(context); } context.SaveChanges(); }
/// <summary> /// Initializes the needed databases after ensuring creation. /// </summary> /// <param name="services">The given service provider.</param> public static void Initialize(IServiceProvider services) { // Get required services var urc_db = services.GetRequiredService <URC_Context>(); var user_roles_db = services.GetRequiredService <UsersRolesDB>(); var userManager = services.GetRequiredService <UserManager <URCUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); // Ensure database creation urc_db.Database.EnsureCreated(); user_roles_db.Database.EnsureCreated(); // Initialize Opportunities/Skills/Tags Opportunity_Seeding.Initialize(urc_db); // Initialize UserRolesDB SeedUsersRolesDB.Initialize(userManager, roleManager, user_roles_db).Wait(); // Initialize Student Applications Student_Application_Seeding.Initialize(urc_db, userManager); }