Ejemplo n.º 1
0
        public static async Task SeedUsers(UserManager <IdentityUser> userManager, BookShopDb context)
        {
            string username = "******";
            string password = "******";

            if (await userManager.FindByNameAsync(username) == null)
            {
                User admin = new User()
                {
                    UserName = username, Email = username
                };
                IdentityResult result = await userManager.CreateAsync(admin, password);

                if (result.Succeeded)
                {
                    var bucket = new Bucket()
                    {
                        User = admin, UserId = admin.Id
                    };
                    admin.Bucket = bucket;
                    await context.Buckets.AddAsync(bucket);

                    await context.SaveChangesAsync();

                    await userManager.AddToRoleAsync(admin, "Admin");

                    await userManager.AddToRoleAsync(admin, "Reader");
                }
            }
        }
Ejemplo n.º 2
0
 public static async Task SeedData(UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager, BookShopDb context)
 {
     await SeedRoles(roleManager);
     await SeedUsers(userManager, context);
 }