예제 #1
0
        public async Task <ActionResult> AddComment([FromBody] MovieCommentInput input)
        {
            var user = await UserController.GetUserFromTokenAsync(_userRepository, Request);

            var movieId = new ObjectId(input.MovieId);
            var result  = await _commentsRepository.AddCommentAsync(user, movieId, input.Comment);

            return(result != null
                ? (ActionResult)Ok(new CommentResponse(
                                       result.Comments.OrderByDescending(d => d.Date).ToList()))
                : BadRequest(new CommentResponse()));
        }
예제 #2
0
        public async Task <IActionResult> Post(string userName, string title, [FromBody] Comment comment)
        {
            try
            {
                comment.Author = GetClaimByName(SUB);

                if (await _commentsRepository.AddCommentAsync(userName, title, comment))
                {
                    return(Ok());
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"Error while adding a comment\n {e.Message}");
            }

            return(BadRequest());
        }
예제 #3
0
        public async Task <ActionResult> AddPost([FromBody] Comment comment)
        {
            var response = await _commentsRepository.AddCommentAsync(comment);

            return(response.Comment != null?Ok(new CommentResponse(response.Comment)) : Ok(response));
        }