public async Task UpdateVideoAsync(string videoId, UpdateVideoModel model) { var videoEntity = await this.FairplaytubeDatabaseContext.VideoInfo .SingleOrDefaultAsync(p => p.VideoId == videoId); if (videoEntity == null) { throw new CustomValidationException($"Unable to find video with Id: {videoId}"); } videoEntity.Price = model.Price; await this.FairplaytubeDatabaseContext.SaveChangesAsync(); }
public async Task <IActionResult> UpdateMyVideo(string videoId, UpdateVideoModel model, CancellationToken cancellationToken) { var userObjectId = this.CurrentUserProvider.GetObjectId(); if (!await this.VideoService.IsVideoOwnerAsync(videoId, userObjectId, cancellationToken)) { throw new CustomValidationException($"User {userObjectId} is not allowed to modify Video: {videoId}"); } await this.VideoService.UpdateVideoAsync(videoId, model); return(Ok()); }
public async Task UpdateMyVideoAsync(string videoId, UpdateVideoModel updateVideoModel) { var authorizedHttpClient = this.HttpClientService.CreateAuthorizedClient(); var response = await authorizedHttpClient.PutAsJsonAsync($"{ApiRoutes.VideoController.UpdateMyVideo}" + $"?videoId={videoId}", updateVideoModel); if (!response.IsSuccessStatusCode) { ProblemHttpResponse problemHttpResponse = await response.Content.ReadFromJsonAsync <ProblemHttpResponse>(); if (problemHttpResponse != null) { throw new CustomValidationException(problemHttpResponse.Detail); } else { throw new CustomValidationException(response.ReasonPhrase); } } }