示例#1
0
        public static void SeedUsers(IUserDataContext userDataContext, IPhotosDataContext photosDataContext)
        {
            if (!userDataContext.GetAllUsersByLastActive().Result.Any())
            {
                System.Console.WriteLine("Seeding users...");
                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();
                    userDataContext.Add(user);

                    foreach (var photo in user.PhotosFromSeed)
                    {
                        photo.UserId = userDataContext.GetByUsername(user.Username).Result.Id;
                        photosDataContext.Add(photo);
                    }
                }
                System.Console.WriteLine("User Seed complete.");
            }
        }
 public async Task <bool> Add <T>(T entity) where T : class
 {
     if (typeof(T) == typeof(User))
     {
         return(await _userDataContext.Add(entity as User));
     }
     else if (typeof(T) == typeof(Like))
     {
         return(await _likesDataContext.Add(entity as Like));
     }
     else if (typeof(T) == typeof(Photo))
     {
         return(await _photosDataContext.Add(entity as Photo));
     }
     else if (typeof(T) == typeof(Message))
     {
         return(await _messagesDataContext.Add(entity as Message));
     }
     else
     {
         throw new NotImplementedException();
     }
 }