samples/Folke.Identity.Elm.Sample/Models/SampleData.cs
/// <summary>
/// Creates a store manager user who can manage the inventory.
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
Creates a store manager user who can manage the inventory.
Creates a store manager user who can manage the inventory .
private static async Task CreateAdminUser(IServiceProvider serviceProvider)
        {
            var options = serviceProvider.GetRequiredService<IOptions<IdentityDbContextOptions>>();
            const string adminRole = "Administrator";
            var userManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
            var roleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
            if (!await roleManager.RoleExistsAsync(adminRole))
            {
                await roleManager.CreateAsync(new IdentityRole { Name =  adminRole });
            }
            var user = await userManager.FindByNameAsync(options.Value.DefaultAdminUserName);
            if (user == null)
            {
                user = new ApplicationUser { UserName = options.Value.DefaultAdminUserName };
                await userManager.CreateAsync(user, options.Value.DefaultAdminPassword);
                await userManager.AddToRoleAsync(user, adminRole);
                await userManager.AddClaimAsync(user, new Claim("ManageStore", "Allowed"));
            }
        }
private static async Task CreateAdminUser ( IServiceProvider serviceProvider ) { var options = serviceProvider . GetRequiredService < IOptions < IdentityDbContextOptions > > ( ) ; const string adminRole = " " ; var userManager = serviceProvider . GetRequiredService < UserManager < ApplicationUser > > ( ) ; var roleManager = serviceProvider . GetRequiredService < RoleManager < IdentityRole > > ( ) ; if ( ! await roleManager . RoleExistsAsync ( adminRole ) ) { await roleManager . CreateAsync ( new IdentityRole { Name = adminRole } ) ; } var user = await userManager . FindByNameAsync ( options . Value . DefaultAdminUserName ) ; if ( user == null ) { user = new ApplicationUser { UserName = options . Value . DefaultAdminUserName } ; await userManager . CreateAsync ( user , options . Value . DefaultAdminPassword ) ; await userManager . AddToRoleAsync ( user , adminRole ) ; await userManager . AddClaimAsync ( user , new Claim ( " " , " " ) ) ; } }
Creates a store manager user who can manage the inventory.
Creates a store manager user who can manage the inventory .
None
serviceProvider
IServiceProvider
None