public static void EnsureSeeded(this BoilerplateContext context) { RolesSeed.Seed(context); context.SaveChanges(); UserSeed.Seed(context); context.SaveChanges(); }
private static async Task SeedIdentity(IHost host) { using var serviceScope = host.Services.CreateScope(); var roleManager = serviceScope.ServiceProvider .GetRequiredService <RoleManager <IdentityRole> >(); var userManager = serviceScope.ServiceProvider .GetRequiredService <UserManager <IdentityUser> >(); await RolesSeed.Seed(roleManager); await UsersSeed.Seed(userManager); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //if (env.IsDevelopment()) //{ app.UseDeveloperExceptionPage(); app.UseBrowserLink(); //} //else //{ // app.UseExceptionHandler("/Home/Error"); //} app.UseStaticFiles(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); IServiceScopeFactory scopeFactory = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>(); using (IServiceScope scope = scopeFactory.CreateScope()) { var profilesRepository = scope.ServiceProvider.GetRequiredService <IProfilesRepository>(); ProfilesSeed.Seed(profilesRepository); var userManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); var usersSeed = new UsersSeed(profilesRepository); usersSeed.Seed(userManager).Wait(); RolesSeed.Seed(roleManager).Wait(); UserRolesSeed.Seed(userManager).Wait(); } }
/// <inheritdoc /> protected override async void Seed(ApplicationDbContext context) { context.Campuses.AddOrUpdate(CampusesSeed.ToArray()); await context.SaveChangesAsync(); context.Countries.AddOrUpdate(CountriesSeed.ToArray()); await context.SaveChangesAsync(); context.Modules.AddOrUpdate(ModulesSeed.ToArray()); await context.SaveChangesAsync(); context.Roles.AddOrUpdate(RolesSeed.ToArray()); await context.SaveChangesAsync(); context.Runs.AddOrUpdate(RunsSeed.ToArray()); await context.SaveChangesAsync(); context.Assignments.AddOrUpdate(AssignmentsSeed.ToArray()); await context.SaveChangesAsync(); context.Books.AddOrUpdate(BooksSeed.ToArray()); await context.SaveChangesAsync(); context.Courses.AddOrUpdate(CoursesSeed.ToArray()); await context.SaveChangesAsync(); context.CourseModules.AddOrUpdate(CourseModulesSeed.ToArray()); await context.SaveChangesAsync(); context.Users.AddOrUpdate(UsersSeed.ToArray()); await context.SaveChangesAsync(); context.UserRoles.AddOrUpdate(UserRolesSeed.ToArray()); await context.SaveChangesAsync(); context.Results.AddOrUpdate(ResultsSeed.ToArray()); await context.SaveChangesAsync(); context.Rentals.AddOrUpdate(RentalsSeed.ToArray()); await context.SaveChangesAsync(); context.Enrolments.AddOrUpdate(EnrolmentsSeed.ToArray()); await context.SaveChangesAsync(); context.Rooms.AddOrUpdate(RoomsSeed.ToArray()); await context.SaveChangesAsync(); context.Lectures.AddOrUpdate(LecturesSeed.ToArray()); await context.SaveChangesAsync(); context.Halls.AddOrUpdate(HallsSeed.ToArray()); await context.SaveChangesAsync(); context.Libraries.AddOrUpdate(LibrariesSeed.ToArray()); await context.SaveChangesAsync(); context.LibraryBooks.AddOrUpdate(LibraryBooksSeed.ToArray()); await context.SaveChangesAsync(); context.Graduations.AddOrUpdate(GraduationsSeed.ToArray()); await context.SaveChangesAsync(); }
private void SeedData(UserManager <AppUser> userManager, RoleManager <IdentityRole> roleManager) { RolesSeed.Seed(roleManager); SeedUsers(userManager); }