Пример #1
0
        /// <summary>
        /// A method that seeds the database with initial realistic data.
        /// </summary>
        /// <param name="dbContext">An extended <see cref="DbContext"/> for the Identity framework.</param>
        public static void Seed <TUser, TRole>(this ExtendedIdentityDbContext <TUser, TRole> dbContext)
            where TUser : User, new()
            where TRole : Role, new()
        {
            // Create an admin account.
            const string adminEmail = "*****@*****.**";
            var          admin      = new TUser {
                Id                   = "ab9769f1-d532-4b7d-9922-3da003157ebd",
                Admin                = true,
                ConcurrencyStamp     = $"{Guid.NewGuid()}",
                CreateDate           = DateTime.UtcNow,
                Email                = adminEmail,
                EmailConfirmed       = true,
                LockoutEnabled       = false,
                NormalizedEmail      = adminEmail.ToUpper(),
                NormalizedUserName   = adminEmail.ToUpper(),
                PasswordHash         = "AH6SA/wuxp9YEfLGROaj2CgjhxZhXDkMB1nD8V7lfQAI+WTM4lGMItjLhhV5ASsq+Q==",
                PhoneNumber          = "69XXXXXXXX",
                PhoneNumberConfirmed = true,
                SecurityStamp        = $"{Guid.NewGuid()}",
                UserName             = adminEmail
            };

            admin.GenerateDeveloperTotp();
            dbContext.Users.Add(admin);
            dbContext.UserClaims.Add(new IdentityUserClaim <string> {
                ClaimType  = JwtClaimTypes.GivenName,
                ClaimValue = "Indice",
                UserId     = admin.Id
            });
            dbContext.UserClaims.Add(new IdentityUserClaim <string> {
                ClaimType  = JwtClaimTypes.FamilyName,
                ClaimValue = "Company",
                UserId     = admin.Id
            });
            dbContext.Users.AddRange(InitialUsers <TUser> .Get(2000));
            dbContext.ClaimTypes.AddRange(InitialClaimTypes.Get());
            dbContext.Roles.AddRange(InitialRoles <TRole> .Get());
            dbContext.SaveChanges();
        }