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; }
public static void insertMainUser(UserModel user) { MySqlOperations.InsertIntoTable("INSERT INTO `vk_app`.`user` (`UserID`,`FirstName`,`SecondName`) VALUES (" + @user.Id + ",'" + @user.FirstName + "','" + @user.LastName + "');"); for (int j = 0; j < user.Posts.Count; j++) { MySqlOperations.InsertIntoTable("INSERT INTO `vk_app`.`userposts` (`userId`, `postId`, `CountLikes`, `Date`, `postText`) VALUES (" + @user.Id + ", " + @user.Posts[j].id + ", " + @user.Posts[j].likesCount + ", '" + @user.Posts[j].Date.ToString("yyyy-MM-dd HH:mm:ss") + "', '" + @user.Posts[j].text + "');"); } }
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 InsertMainUser(UserModel user) { MySqlQuery.insertMainUser(user); }