public override Task <PostResponse> AddPost(PostRequest request, ServerCallContext context) { Post postToAdd = Post.Create(request.Description, request.Domain, DateTime.Now); if (request.Comments.Count > 0) { foreach (var comment in request.Comments) { postToAdd.AddComment(Comment.Create(comment.Text)); } } Post post = PostCommentAPI.AddPost(postToAdd); //PostResponse postResponse = _mapper.Map<PostResponse>(post); PostResponse postResponse = new PostResponse() { PostId = post.PostId.ToString(), Domain = post.Domain, Description = post.Description, Date = DateTimeOffset.Now.ToTimestamp() }; foreach (var comment in post.Comments) { postResponse.Comments.Add(new CommentResponse() { CommentId = comment.CommentId.ToString(), Text = comment.Text }); } return(Task.FromResult(postResponse)); }
private PostResponse ConvertPostToPostResponse(Post post) { PostResponse postResponse = new PostResponse() { PostId = post.PostId.ToString(), Domain = post.Domain, Description = post.Description, Date = DateTimeOffset.Now.ToTimestamp() }; foreach (var comment in post.Comments) { postResponse.Comments.Add(new CommentResponse() { CommentId = comment.CommentId.ToString(), Text = comment.Text }); } return(postResponse); }