public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
//Temp code
var roleStore = new RoleStore<IdentityRole>(new ApplicationDbContext());
var roleManager = new RoleManager<IdentityRole>(roleStore);
await roleManager.CreateAsync(new IdentityRole("CanManageMovie"));
await UserManager.AddToRoleAsync(user.Id, "CanManageMovie");
3.Register a admin account in the home page
4.Remove the code on step 2 and rebuild
5.On nuget package condole, type:
add-migration "seed users"
6.Go to server explorer, copy the script from AspNetUsers, AspNetRoles, AspNetUserRoles and paste them on the migration file