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

                    user.Username     = user.Username.ToLower();
                    user.PasswordHash = passwordHash;
                    user.PasswordSalt = passwordSalt;
                    context.Add(user);
                }
                context.SaveChanges();
            }
        }
コード例 #2
0
 public void Add <T>(T entity) where T : class
 {
     context.Add(entity);
 }