コード例 #1
0
        protected async override void Seed(ApplicationDbContext context)
        {
            context.Companies.Add(new Company {
                Name = "Microsoft"
            });
            context.Companies.Add(new Company {
                Name = "Apple"
            });
            context.Companies.Add(new Company {
                Name = "Google"
            });
            context.SaveChanges();

            // Set up two initial users with different role claims:
            var dino = new MyUser {
                Email = "*****@*****.**"
            };
            var dino2 = new MyUser {
                Email = "*****@*****.**"
            };

            dino.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Name, UserId = dino.Id, ClaimValue = dino.Email
            });
            dino.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Role, UserId = dino.Id, ClaimValue = "Admin"
            });

            dino2.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Name, UserId = dino2.Id, ClaimValue = dino2.Email
            });
            dino2.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Role, UserId = dino2.Id, ClaimValue = "User"
            });

            var store = new MyUserStore(context);
            await store.AddUserAsync(dino, "DinosPassword");

            await store.AddUserAsync(dino2, "Dino2sPassword");
        }
コード例 #2
0
        protected async override void Seed(ApplicationDbContext context)
        {
            context.Companies.Add(new Company {
                Name = "Microsoft"
            });
            context.Companies.Add(new Company {
                Name = "Apple"
            });
            context.Companies.Add(new Company {
                Name = "Google"
            });
            context.SaveChanges();

            // Set up two initial users with different role claims:
            var john = new MyUser {
                Email = "*****@*****.**"
            };
            var jimi = new MyUser {
                Email = "*****@*****.**"
            };

            john.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Name, UserId = john.Id, ClaimValue = john.Email
            });
            john.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Role, UserId = john.Id, ClaimValue = "Admin"
            });

            jimi.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Name, UserId = jimi.Id, ClaimValue = jimi.Email
            });
            jimi.Claims.Add(new MyUserClaim {
                ClaimType = ClaimTypes.Role, UserId = john.Id, ClaimValue = "User"
            });

            var store = new MyUserStore(context);
            await store.AddUserAsync(john, "JohnsPassword");

            await store.AddUserAsync(jimi, "JimisPassword");
        }