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())); }
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()); }
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)); }