private static void SeedRoles(RoleManager <IdentityRole> roleManager, SeedDataValues seedDataValues) { if (!roleManager.RoleExistsAsync(seedDataValues.AdminRoleName).Result) { var role = new IdentityRole { Name = seedDataValues.AdminRoleName }; var result = roleManager.CreateAsync(role).Result; } if (!roleManager.RoleExistsAsync(seedDataValues.UserRoleName).Result) { var role = new IdentityRole { Name = seedDataValues.UserRoleName }; var result = roleManager.CreateAsync(role).Result; } }
private static async Task SeedUsersAsync(UserManager <IdentityUser> userManager, SeedDataValues seedDataValues) { if (userManager.FindByNameAsync(seedDataValues.AdminUserName).Result == null) { var user = new ApplicationUser { UserName = seedDataValues.AdminUserName, Email = seedDataValues.AdminEmail }; var result = userManager.CreateAsync(user, seedDataValues.AdminPassword).Result; if (result.Succeeded) { userManager.AddToRoleAsync(user, seedDataValues.AdminRoleName).Wait(); var code = await userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code)); await userManager.ConfirmEmailAsync(user, code); } } }