public async Task <CreateCommentResponse> CreatePostComment(Guid postId, [FromBody] CreateCommentRequest model)
        {
            var comment = new Models.PostComment
            {
                Comment   = model.Comment,
                OwnerId   = CurrentUserId,
                OwnerName = User.Identity.Name,
                PostId    = postId
            };

            await _postCommentRepo.AddAsync(comment);

            var response = new CreateCommentResponse
            {
                Id          = comment.Id,
                Comment     = comment.Comment,
                PostId      = comment.PostId,
                OwnerName   = comment.OwnerName,
                CreatedDate = comment.Created
            };

            await _postMessageHubContext.Clients.All.InvokeAsync("AddCommentSuccess", response);

            return(response);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateCommentResponse response = new CreateCommentResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Comment", targetDepth))
                {
                    var unmarshaller = CommentUnmarshaller.Instance;
                    response.Comment = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
예제 #3
0
        public async Task <IActionResult> CreateComment([FromHeader(Name = "X-Account-Id")] Guid creatorId, [FromRoute] Guid postId, [FromBody] string content)
        {
            CreateCommentResponse response = await mediator.Send(new CreateCommentRequest(creatorId, postId, content));

            return(CreatedAtAction(nameof(GetCommentById), new { postId = postId, commentId = response.Id }, response));
        }