Esempio n. 1
0
        public static List<UserModel> AddFriends(List<int> friendsId, int ownerId)
        {
            List<UserModel> friendsList = new List<UserModel>();

             for (int i = 0; i < 20; i++)
            {
               JObject friendInfo = ApiVkRequests.GetUserInfo(friendsId[i].ToString());
               UserModel friend = new UserModel();

               List<PostModel> postsList = new List<PostModel>();
               postsList.Clear();
               friend.ownerId = ownerId;
               friend.Id = Convert.ToInt32(Parser.GetUserId(friendInfo));
               friend.FirstName = Parser.GetUserFirstName(friendInfo);
               friend.LastName = Parser.GetUserLastName(friendInfo);
               friend.City = Parser.GetUserCity(friendInfo);
               List<int> postsId = Parser.GetUserPosts(ApiVkRequests.GetUserPosts(friendsId[i]));

               for (int j = 0; j < postsId.Count; j++)
               {
                   PostModel postModel = new PostModel();
                   postModel.userId = friendsId[i];
                   postModel.id = postsId[j];
                   postModel.Date = Parser.GetDate(ApiVkRequests.GetUserPosts(friendsId[i]),postsId[j]);
                   postModel.likesCount = Parser.GetLikes(ApiVkRequests.GetUserPosts(friendsId[i]), postsId[j]);
                   postsList.Add(postModel);
               }

               Console.WriteLine(postsList.Count);
               friend.Posts = postsList;
               friendsList.Add(friend);

            }
             return friendsList;
        }
Esempio n. 2
0
        public static UserModel AddMainUser(int userId)
        {
            UserModel user = new UserModel();
             List<PostModel> posts = new List<PostModel>();
             PostModel post = new PostModel();
             JObject userInfo = ApiVkRequests.GetUserInfo(userId.ToString());
             user.Id = Convert.ToInt32(Parser.GetUserId(userInfo));
             user.FirstName = Parser.GetUserFirstName(userInfo);
             user.LastName = Parser.GetUserLastName(userInfo);
             List<int> postsId = Parser.GetUserPosts(ApiVkRequests.GetUserPosts(userId));
             for (int j = 0; j < postsId.Count; j++)
             {
                 post.userId = userId;
                 post.id = postsId[j];
                 post.Date = Parser.GetDate(ApiVkRequests.GetUserPosts(userId), postsId[j]);
                 posts.Add(post);
             }

             user.Posts = posts;
             return user;
        }
        public static void UpdateAllFriends(string currentOwnerId)
        {
            UserUpdater.AddNewFriends(UserUpdater.CheckCurrentFriends(UserUpdater.ReturnFriendsList(currentOwnerId)), currentOwnerId);
            List<int> friendsId = Parser.ParseFriendsId(ApiVkRequests.GetUserFriends(currentOwnerId));
            List<PostModel> postsList = new List<PostModel>();

            foreach(int friend in friendsId)
            {
                MySqlQuery.DeleteFriendPosts(friend.ToString());

                List<int> postsId = Parser.GetUserPosts(ApiVkRequests.GetUserPosts(friend));

                for (int j = 0; j < postsId.Count; j++)
                {
                    PostModel postModel = new PostModel();
                    postModel.userId = friend;
                    postModel.id = postsId[j];
                    postModel.Date = Parser.GetDate(ApiVkRequests.GetUserPosts(friend), postsId[j]);
                    postsList.Add(postModel);

                }
                MySqlQuery.insertNewPosts(postsList, friend.ToString());
            }
        }