Beispiel #1
0
 public static void SeedUsers(DatingAppContext context)
 {
     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.PasswordHash = passwordhash;
             user.PasswordSalt = passwordSalt;
             user.Username     = user.Username.ToLower();
             context.Users.Add(user);
         }
         context.SaveChanges();
     }
 }
Beispiel #2
0
        public static void SeedUsers(DatingAppContext context)
        {
            if (context.UserModels.Any())
            {
                return;
            }

            var userData = System.IO.File.ReadAllText("Data/UserSeedData.json");

            var users = JsonConvert.DeserializeObject <List <UserModel> >(userData);

            foreach (var user in users)
            {
                (user.PasswordHash, user.PasswordSalt) = CreatePassWordHash("password");
                user.Username = user.Username.ToLower();

                context.UserModels.Add(user);
            }

            context.SaveChanges();
        }