コード例 #1
0
ファイル: CommentsController.cs プロジェクト: Marcin99b/Hated
        public async Task <IActionResult> AddAsync([FromBody] CreateComment newComment)
        {
            try
            {
                var commentId = await _postCommentService.AddAsync(User.GetUserId(), newComment.PostId, newComment.Content);

                return(Created($"comments/post/{newComment.PostId}/comment/{commentId}", null));
            }
            catch (Exception e)
            {
                _logger.LogError($"Returning exception: {e.Message}");
                return(Json(new ExceptionDto
                {
                    Error = e.Message
                }));
            }
        }
コード例 #2
0
        public async Task <ActionResult> Comment(int postId, string commentBody)
        {
            await _postCommentService.AddAsync(UserHelper.UserId.Value, postId, commentBody);

            return(RedirectToAction(nameof(Index), "Read", new { postId = postId }));
        }