到目前为止我做了什么
public class SeedIdentity
{
public static async Task Seed(IApplicationBuilder app)
{
var identityContext = app.ApplicationServices.GetRequiredService<ApplicationIdentityDbContext>();
identityContext.Database.Migrate();
if (!identityContext.Roles.Any(i => i.Name == "Admin" && i.Name == "User"))
{
var roleStore = new RoleStore<IdentityRole>(identityContext);
var roleManager = new RoleManager<IdentityRole>(roleStore, null, null, null, null);
var adminRole = new IdentityRole { Name = "admin" };
var userRole = new IdentityRole { Name = "user" };
await roleManager.CreateAsync(adminRole);
await roleManager.CreateAsync(userRole);
identityContext.SaveChanges();
}
if (!identityContext.Users.Any(i => i.UserName == "akinaldemir"))
{
var userStore = new UserStore<ApplicationUser>(identityContext);
var userManager = new UserManager<ApplicationUser>(userStore, null, null, null,null, null, null, null, null);
var admin = new ApplicationUser()
{
UserName = "akinaldemir",
Email = "akinaldemir@gmail.com"
};
await userManager.CreateAsync(admin, "Abc12!jtre");
await userManager.AddToRoleAsync(admin, "admin");
identityContext.SaveChanges();
}
}
}