コード例 #1
0
        public void SeedUsers()
        {
            if (!_context.Users.Any())
            {
                var userData = File.ReadAllText("Data/UserDataSeed.json");
                var users    = JsonConvert.DeserializeObject <List <User> >(userData);
                foreach (var user in users)
                {
                    CreatePasswordHash("password", out byte[] passwordHash, out byte[] passwordSalt);
                    user.PasswordHash = passwordHash;
                    user.PasswordSalt = passwordSalt;
                    user.UserName     = user.UserName.ToLower();
                }

                _context.AddRange(users);
                _context.SaveChanges();
            }
        }