I have managed to seed the admin's details like the username and password, so they appear in the table. However, the issue I am having is the role "admin" is not being saved anywhere in the table. Am I missing something here? I am new to asp.net core so I'm just trying to wrap my head around it.
Below is my seeding class:
public class ApplicationDbInitializer
{
public static void SeedUsers(UserManager<IdentityUser> userManager)
{
if (userManager.FindByEmailAsync("abc@outlook.com").Result == null)
{
IdentityUser user = new IdentityUser
{
UserName = "abc@outlook.com",
Email = "abc@outlook.com"
};
IdentityResult result = userManager.CreateAsync(user, "Passwordtest123!").Result;
if (result.Succeeded)
{
userManager.AddToRoleAsync(user, "Admin").Wait();
}
}
}
}
Below is my configure method signature:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager<IdentityUser> userManager)
Below is me invoking my seed method:
ApplicationDbInitializer.SeedUsers(userManager);
Below is my add identity:
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<RestaurantWebContext>();
Is there something in the code that is missing, I can't see admin show up in the role table or the user table.