public static void SeedRoles(FushanContext fushanContext) { fushanContext.Roles.AddRange(new[] { new Role { Id = Guid.NewGuid(), Name = "Admin", NormalizedName = "Admin", CreatedByUsername = "******", CreatedOn = DateTimeOffset.Now, UpdatedByUsername = "******", UpdatedOn = DateTimeOffset.Now, }, new Role { Id = Guid.NewGuid(), Name = "User", NormalizedName = "User", CreatedByUsername = "******", CreatedOn = DateTimeOffset.Now, UpdatedByUsername = "******", UpdatedOn = DateTimeOffset.Now, } }); }
public static void SeedUsers(UserManager <AppUser> userManager, FushanContext fushanContext) { if (userManager.FindByEmailAsync("*****@*****.**").Result == null) { var user = new AppUser { UserName = "******", Email = "*****@*****.**", CreatedByUsername = "******", CreatedOn = DateTimeOffset.Now, UpdatedByUsername = "******", UpdatedOn = DateTimeOffset.Now, }; IdentityResult result = userManager.CreateAsync(user, "Tkadmin1!").Result; if (result.Succeeded) { userManager.AddToRoleAsync(user, "Admin").Wait(); } } }
public static void SeeDepartments(FushanContext fushanContext) { var rows = fushanContext.Departments.Count(); if (rows > 0) { return; } for (int i = 0; i < 10; i++) { var departments = new List <Department>(); var count = 0; while (count < 100000) { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var ranString = new string(Enumerable.Repeat(chars, 6) .Select(s => s[random.Next(s.Length)]).ToArray()); var department = new Department { Id = Guid.NewGuid(), Name = ranString, DepartmentId = ranString, CreatedByUsername = "******", CreatedOn = DateTimeOffset.Now, UpdatedByUsername = "******", UpdatedOn = DateTimeOffset.Now, }; departments.Add(department); count++; } fushanContext.Departments.AddRange(departments); fushanContext.SaveChanges(); i++; } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, FushanContext fushanContext, UserManager <AppUser> userManager) { LogManager.LoadConfiguration(String.Concat(Directory.GetCurrentDirectory(), "/nlog.config")); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { //app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } //app.ConfigureExceptionHandler(logger); app.ConfigureCustomExceptionMiddleware(); app.UseHttpsRedirection(); app.UseStaticFiles(); if (!env.IsDevelopment()) { app.UseSpaStaticFiles(); } app.UseRouting(); app.UseAuth(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); }); app.UseOpenApi(); app.UseSwaggerUi3(); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); //app.UseSwagger(); //app.UseSwaggerUI(c => //{ // c.RoutePrefix = ""; // c.SwaggerEndpoint("/swagger/v1/swagger.json", "My Music V1"); //}); fushanContext.Database.EnsureCreated(); if (fushanContext.Users.Count() == 0) { FushanDbInitializer.SeedRoles(fushanContext); FushanDbInitializer.SeedUsers(userManager, fushanContext); } //FushanDbInitializer.SeeDepartments(fushanContext); }