private static async Task addUserRoles(IServiceProvider service) { var userManager = service.GetService <UserManager <ApplicationUser> >(); var randomUser = await userManager.Users.FirstOrDefaultAsync(); var roleName = RoleExtensions.GetRoleName(UserRoles.Doctor); await userManager.AddToRoleAsync(randomUser, roleName); }
private static async Task createRoles(IServiceProvider service) { var roleManager = service.GetService <RoleManager <IdentityRole> >(); var roles = Enum.GetValues(typeof(UserRoles)); IdentityResult roleResult; foreach (var roleObject in roles) { var role = RoleExtensions.GetRoleName(roleObject); var roleExist = await roleManager.RoleExistsAsync(role); if (!roleExist) { roleResult = await roleManager.CreateAsync(new IdentityRole(role)); } } }