Exemple #1
0
        private async Task SeedAsync(ApplicationDbContext context)
        {
            if (!context.Roles.Any(r => r.Name == "AppAdmin"))
            {
                var store   = new CustomRoleStore(context);
                var manager = new ApplicationRoleManager(store);
                var role    = new AppRole {
                    Name = "AppAdmin"
                };

                await manager.CreateAsync(role);

                var roleGreo = new AppRole {
                    Name = "AppGreo"
                };
                await manager.CreateAsync(roleGreo);
            }
            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store   = new CustomUserStore(context);
                var manager = new ApplicationUserManager(store);
                var user    = new AppUser
                {
                    FirstName            = "Dmitry", LastName = "Chumak",
                    UserName             = "******",
                    SubdivisionId        = 0,
                    Email                = "*****@*****.**",
                    EmailConfirmed       = true,
                    PhoneNumber          = "0123456789",
                    PhoneNumberConfirmed = true
                };


                await manager.CreateAsync(user, "Qwerty123_");



                //Add User To Role
                await manager.AddToRoleAsync(user.Id, "AppAdmin");

                ////Add User Claims
                await manager.AddClaimAsync(user.Id, new Claim(ClaimTypes.GivenName, "A Person"));

                await manager.AddClaimAsync(user.Id, new Claim(ClaimTypes.Gender, "Man"));

                await manager.AddClaimAsync(user.Id, new Claim(ClaimTypes.DateOfBirth, "01.01.2001"));
            }
            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store     = new CustomUserStore(context);
                var manager   = new ApplicationUserManager(store);
                var userGreo1 = new AppUser
                {
                    FirstName            = "greo401",
                    LastName             = "greo401",
                    UserName             = "******",
                    SubdivisionId        = 1,
                    Email                = "*****@*****.**",
                    EmailConfirmed       = true,
                    PhoneNumber          = "0123456789",
                    PhoneNumberConfirmed = true
                };


                await manager.CreateAsync(userGreo1, "Greo401_");

                //Add User To Role
                await manager.AddToRoleAsync(userGreo1.Id, "AppGreo");
            }
            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store     = new CustomUserStore(context);
                var manager   = new ApplicationUserManager(store);
                var userGreo2 = new AppUser
                {
                    FirstName            = "greo402",
                    LastName             = "greo402",
                    UserName             = "******",
                    SubdivisionId        = 2,
                    Email                = "*****@*****.**",
                    EmailConfirmed       = true,
                    PhoneNumber          = "0123456789",
                    PhoneNumberConfirmed = true
                };


                await manager.CreateAsync(userGreo2, "Greo402_");

                //Add User To Role
                await manager.AddToRoleAsync(userGreo2.Id, "AppGreo");
            }
        }
        private async Task SeedAsync(ApplicationDbContext context)
        {
            if (!context.Roles.Any(r => r.Name == "AppAdmin"))
            {
                var store   = new CustomRoleStore(context);
                var manager = new ApplicationRoleManager(store);
                var role    = new AppRole {
                    Name = "AppAdmin"
                };

                await manager.CreateAsync(role);

                var roleGreo = new AppRole {
                    Name = "AppClient"
                };
                await manager.CreateAsync(roleGreo);
            }
            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store   = new CustomUserStore(context);
                var manager = new ApplicationUserManager(store);
                var user    = new AppUser
                {
                    FirstName            = "Sergey", LastName = "Admin",
                    UserName             = "******",
                    SubdivisionId        = 0,
                    Email                = "*****@*****.**",
                    EmailConfirmed       = true,
                    PhoneNumber          = "0123456789",
                    PhoneNumberConfirmed = true
                };


                await manager.CreateAsync(user, "15sevenNation");



                //Add User To Role
                await manager.AddToRoleAsync(user.Id, "AppAdmin");

                ////Add User Claims
                await manager.AddClaimAsync(user.Id, new Claim(ClaimTypes.GivenName, "A Person"));

                await manager.AddClaimAsync(user.Id, new Claim(ClaimTypes.Gender, "Man"));

                await manager.AddClaimAsync(user.Id, new Claim(ClaimTypes.DateOfBirth, "01.01.2001"));
            }
            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store     = new CustomUserStore(context);
                var manager   = new ApplicationUserManager(store);
                var userGreo1 = new AppUser
                {
                    FirstName            = "Bot228",
                    LastName             = "Bot228",
                    UserName             = "******",
                    SubdivisionId        = 1,
                    Email                = "*****@*****.**",
                    EmailConfirmed       = true,
                    PhoneNumber          = "0123456789",
                    PhoneNumberConfirmed = true
                };


                await manager.CreateAsync(userGreo1, "Bot2281");

                //Add User To Role
                await manager.AddToRoleAsync(userGreo1.Id, "AppClient");
            }
            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store     = new CustomUserStore(context);
                var manager   = new ApplicationUserManager(store);
                var userGreo2 = new AppUser
                {
                    FirstName            = "Bot220",
                    LastName             = "Bot220",
                    UserName             = "******",
                    SubdivisionId        = 2,
                    Email                = "*****@*****.**",
                    EmailConfirmed       = true,
                    PhoneNumber          = "0123456789",
                    PhoneNumberConfirmed = true
                };


                await manager.CreateAsync(userGreo2, "Bot2201");

                //Add User To Role
                await manager.AddToRoleAsync(userGreo2.Id, "AppClient");
            }
        }