public async Task <IActionResult> AddVideoComment(CreateVideoCommentModel createVideoCommentModel, CancellationToken cancellationToken) { await this.VideoCommentService.AddVideoCommentAsync(createVideoCommentModel, cancellationToken); return(Ok()); }
public async Task AddVideoCommentAsync(CreateVideoCommentModel newCommentModel) { var authorizedHttpClient = this.HttpClientService.CreateAuthorizedClient(); var response = await authorizedHttpClient.PostAsJsonAsync(Constants.ApiRoutes.VideoCommentController.AddVideoComment, newCommentModel); if (!response.IsSuccessStatusCode) { ProblemHttpResponse problemHttpResponse = await response.Content.ReadFromJsonAsync <ProblemHttpResponse>(); if (problemHttpResponse != null) { throw new CustomValidationException(problemHttpResponse.Detail); } else { throw new CustomValidationException(response.ReasonPhrase); } } }
public async Task AddVideoCommentAsync(CreateVideoCommentModel createVideoCommentModel, CancellationToken cancellationToken) { await this.ContentModerationService.CheckMessageModerationAsync(createVideoCommentModel.Comment); var videoEntity = await this.FairplaytubeDatabaseContext.VideoInfo .SingleOrDefaultAsync(p => p.VideoId == createVideoCommentModel.VideoId, cancellationToken : cancellationToken); if (videoEntity is null) { throw new CustomValidationException($"Unable to find {nameof(createVideoCommentModel.VideoId)}: {createVideoCommentModel.VideoId}"); } var commentedUserObjectId = this.CurrentUserProvider.GetObjectId(); var commentedApplicationUser = await this.FairplaytubeDatabaseContext.ApplicationUser .SingleAsync(p => p.AzureAdB2cobjectId.ToString() == commentedUserObjectId, cancellationToken : cancellationToken); await this.FairplaytubeDatabaseContext.VideoComment.AddAsync(new VideoComment() { Comment = createVideoCommentModel.Comment, VideoInfoId = videoEntity.VideoInfoId, ApplicationUserId = commentedApplicationUser.ApplicationUserId, }, cancellationToken : cancellationToken); await this.FairplaytubeDatabaseContext.SaveChangesAsync(cancellationToken : cancellationToken); }