public async Task <IActionResult> UpdateComment(int commentId, [FromBody] UpdateCommentParameters parameters) { var comment = await commentsRepo.FindCommentByIdAsync(commentId, includeDeleted : true).ConfigureAwait(false); if (comment == null) { return(NotFound(new ErrorResponse($"Comment {commentId} not found"))); } if (comment.IsDeleted && await CanEditOrDeleteCommentAsync(comment, UserId).ConfigureAwait(false)) { await commentsRepo.RestoreCommentAsync(commentId).ConfigureAwait(false); } if (!string.IsNullOrEmpty(parameters.Text)) { await UpdateCommentTextAsync(comment, parameters.Text).ConfigureAwait(false); } if (parameters.IsApproved.HasValue) { await UpdateCommentIsApprovedAsync(comment, parameters.IsApproved.Value).ConfigureAwait(false); } if (parameters.IsPinned.HasValue) { await UpdateCommentIsPinnedAsync(comment, parameters.IsPinned.Value).ConfigureAwait(false); } if (parameters.IsCorrectAnswer.HasValue) { await UpdateCommentIsCorrectAnswerAsync(comment, parameters.IsCorrectAnswer.Value).ConfigureAwait(false); } return(Ok(new SuccessResponseWithMessage($"Comment {commentId} successfully updated"))); }
public async Task <ActionResult <CommentResponse> > UpdateComment(int commentId, [FromBody] UpdateCommentParameters parameters) { var comment = await commentsRepo.FindCommentByIdAsync(commentId, includeDeleted : true).ConfigureAwait(false); if (comment == null) { return(NotFound(new ErrorResponse($"Comment {commentId} not found"))); } if (comment.IsDeleted && await CanEditOrDeleteCommentAsync(comment, UserId).ConfigureAwait(false)) { await commentsRepo.RestoreCommentAsync(commentId).ConfigureAwait(false); } parameters.Text?.TrimEnd(); if (!string.IsNullOrEmpty(parameters.Text)) { await UpdateCommentTextAsync(comment, parameters.Text).ConfigureAwait(false); } if (parameters.IsApproved.HasValue) { await UpdateCommentIsApprovedAsync(comment, parameters.IsApproved.Value).ConfigureAwait(false); } if (parameters.IsPinnedToTop.HasValue) { await UpdateCommentIsPinnedAsync(comment, parameters.IsPinnedToTop.Value).ConfigureAwait(false); } if (parameters.IsCorrectAnswer.HasValue) { await UpdateCommentIsCorrectAnswerAsync(comment, parameters.IsCorrectAnswer.Value).ConfigureAwait(false); } return(await Comment(commentId, new CommentParameters { WithReplies = false }).ConfigureAwait(false)); }
public async Task <ActionResult <GameViewModel> > Update([FromQuery] UpdateCommentParameters parameters, CancellationToken cancellationToken) { var result = await _commentService.UpdateComment(parameters.GameId, new Core.Entties.Game.Comment(parameters.Id, parameters.Content, User.GetUserName(), DateTime.UtcNow, parameters.Rating.Value), cancellationToken); return(Ok(GameViewModel.Create(result))); }