/// <inheritdoc /> public async Task UpdateCommentAsync(long commentId, PromotionSentiment newSentiment, string newContent) { AuthorizationService.RequireAuthenticatedUser(); AuthorizationService.RequireClaims(AuthorizationClaim.PromotionsComment); ValidateComment(newContent); PromotionActionSummary resultAction; using (var transaction = await PromotionCommentRepository.BeginUpdateTransactionAsync()) { var oldComment = await PromotionCommentRepository.ReadSummaryAsync(commentId); var campaign = await PromotionCampaignRepository.ReadDetailsAsync(oldComment.Campaign.Id); if (!(campaign.CloseAction is null)) { throw new InvalidOperationException($"Campaign {oldComment.Campaign.Id} has already been closed"); } resultAction = await PromotionCommentRepository.TryUpdateAsync(commentId, AuthorizationService.CurrentUserId.Value, x => { x.Sentiment = newSentiment; x.Content = newContent; }); transaction.Commit(); } PublishActionNotificationAsync(resultAction); }
/// <inheritdoc /> public async Task UpdateCommentAsync(long commentId, PromotionSentiment newSentiment, string newContent) { AuthorizationService.RequireAuthenticatedUser(); AuthorizationService.RequireClaims(AuthorizationClaim.PromotionsComment); if (newContent is null || newContent.Length <= 3) { throw new InvalidOperationException("Comment content must be longer than 3 characters."); } using (var transaction = await PromotionCommentRepository.BeginUpdateTransactionAsync()) { var oldComment = await PromotionCommentRepository.ReadSummaryAsync(commentId); var campaign = await PromotionCampaignRepository.ReadDetailsAsync(oldComment.Campaign.Id); if (!(campaign.CloseAction is null)) { throw new InvalidOperationException($"Campaign {oldComment.Campaign.Id} has already been closed"); } await PromotionCommentRepository.TryUpdateAsync(commentId, AuthorizationService.CurrentUserId.Value, x => { x.Sentiment = newSentiment; x.Content = newContent; }); transaction.Commit(); } }