public List <ClientPost> GetAllPosts(string userId) { List <Post> posts; try { posts = _graphDB.GetAllPosts(userId); } catch (Exception) { throw new FaildToConnectDbException(); } List <ClientPost> postsToClient = new List <ClientPost>(); foreach (var post in posts) { ClientPost clientPost = new ClientPost(post); List <Comment> postComments = _graphDB.GetCommentsForPost(post.PostID); List <MainComment> mainComments = new List <MainComment>(); foreach (var comment in postComments) { MainComment mainComment = new MainComment { Comment = comment, CommentOwner = _graphDB.GetCommentOwner(comment.CommentID), IsLike = _graphDB.IsUserLikeComment(userId, comment.CommentID) }; mainComments.Add(mainComment); //comment.UsersLike = _graphDB.GetLikesForComment(comment.CommentID); } clientPost.Comments = mainComments; clientPost.PostOwner = _graphDB.GetPostOwner(post.PostID); clientPost.IsLike = _graphDB.IsUserLikePost(userId, post.PostID); List <User> usersLike = _graphDB.GetLikesForPost(post.PostID); clientPost.UsersLikes = _graphDB.GetLikesForPost(post.PostID); clientPost.LikeCount = usersLike.Count; postsToClient.Add(clientPost); } return(postsToClient); }