public async Task <IActionResult> UpdateComment([FromBody] UpdateCommentBindingModel updateCommentBindingModel, int commentId) { var user = User.Identity.Name; var result = await _commentService.UpdateComment(updateCommentBindingModel, commentId, user); if (result.ErrorOccurred) { return(BadRequest(result)); } return(Ok(result)); }
public async Task <ResponseDto <BaseModelDto> > UpdateComment(UpdateCommentBindingModel updateCommentBindingModel, int commentId, string userId) { var response = new ResponseDto <BaseModelDto>(); var commentExists = await _commentRepository.ExistAsync(x => x.Id == commentId); if (!commentExists) { response.AddError(Model.Comment, Error.tvShow_NotFound); return(response); } if (userId == null) { response.AddError(Model.Actor, Error.account_Login); return(response); } var comment = await _commentRepository.GetByAsync(x => x.Id == commentId); comment.Content = updateCommentBindingModel.Content; comment.UpdateDateTime = DateTime.Now; if (comment.UserId != userId) { response.AddError(Model.Comment, Error.comment_Author); return(response); } var result = await _commentRepository.UpdateAsync(comment); if (!result) { response.AddError(Model.Category, Error.comment_Updating); return(response); } return(response); }