protected override void Seed(Contexts.AuthContext context) { var systemUser = context.Set <ApplicationUser>().SingleOrDefault(x => x.UserName == "SystemUser"); if (systemUser != null) { return; } systemUser = UserSeedData.Create(context).Result; context.SaveChanges(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; var userManager = services.GetRequiredService <UserManager <User> >(); var identityContext = services.GetRequiredService <StoreContext>(); await identityContext.Database.MigrateAsync(); await UserSeedData.SeedUsersAsync(userManager); CreateHostBuilder(args).Build().Run(); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity <User>() .HasMany(e => e.Roles) .WithOne() .HasForeignKey(e => e.UserId) .IsRequired() .OnDelete(DeleteBehavior.Cascade); modelBuilder.Entity <User>(entity => { entity.HasKey(r => new { r.Id }); entity.ToTable("AspNetUsers"); }); modelBuilder.Entity <IdentityRole <Guid> >(entity => { entity.HasKey(r => new { r.Id }); entity.ToTable("AspNetRoles"); }); modelBuilder.Entity <IdentityUserClaim <Guid> >(entity => { entity.HasKey(r => new { r.Id }); entity.ToTable("AspNetUserClaims"); }); modelBuilder.Entity <IdentityUserRole <Guid> >(entity => { entity.HasKey(r => new { r.UserId, r.RoleId }); entity.ToTable("AspNetUserRoles"); }); modelBuilder.Entity <IdentityUserLogin <Guid> >(entity => { entity.HasKey(l => new { l.LoginProvider, l.ProviderKey, l.UserId }); entity.ToTable("AspNetUserLogins"); }); modelBuilder.Entity <IdentityUserToken <Guid> >(entity => { entity.HasKey(r => r.UserId); entity.ToTable("AspNetUserTokens"); }); UserSeedData.Initialize(modelBuilder); BlogSeedData.Initialize(modelBuilder); PostSeedData.Initialize(modelBuilder); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <CMSContext>(); context.Database.Migrate(); UserSeedData.Initialize(services).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred adding users."); } } host.Run(); }
public static IApplicationBuilder PopulateDatabase(this IApplicationBuilder app) { GameSeedData.PopulateGame(app); UserSeedData.PopulateUser(app); return(app); }