public List <PostModel> getPostModelsForNewFeed(string id) { List <PostModel> postModelList = new List <PostModel>(); List <User> friends = userDao.getAllFriends(id); //loop each friend to get their posts foreach (User friend in friends) { UserAvatarModel userOfPost = new UserAvatarModel() { Id = friend.id, Username = friend.username, Avatar = friend.avatar }; Post latestPost = postDao.getLatestPostOfUser(friend.id); if (latestPost != null) { List <CommentModel> top3CommentModels = commentDao.getTop3CommentModels(latestPost.id); int numberOfLikes = favoriteDao.getNumberOfLikesInPost(latestPost.id); string timeAgo = DateTimeUtils.getTimeAgo(latestPost.time.GetValueOrDefault()); bool isLike = favoriteDao.isLikeByUser(id, latestPost.id); PostModel postModel = new PostModel() { UserOfPost = userOfPost, PostId = latestPost.id, PostContent = latestPost.content, PostImage = latestPost.image, Top3CommentModels = top3CommentModels, NumberLikes = numberOfLikes, Time = latestPost.time, TimeAgo = timeAgo, IsLikeByLoginedUser = isLike }; postModelList.Add(postModel); } } postModelList.Sort(); return(postModelList); }