コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: PromotionsService.cs プロジェクト: trustieee/MODiX
        /// <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();
            }
        }
コード例 #3
0
 public Task Comment(
     [Summary("The ID value of the campaign to be commented upon")]
     long campaignId,
     [Summary("The sentiment of the comment")]
     PromotionSentiment sentiment,
     [Remainder]
     [Summary("The content of the comment")]
     string content)
 => PromotionsService.AddCommentAsync(campaignId, sentiment, content);
コード例 #4
0
        /// <inheritdoc />
        public async Task AddCommentAsync(long campaignId, PromotionSentiment sentiment, string content)
        {
            AuthorizationService.RequireAuthenticatedUser();
            AuthorizationService.RequireClaims(AuthorizationClaim.PromotionsComment);

            ValidateComment(content);

            if (await PromotionCommentRepository.AnyAsync(new PromotionCommentSearchCriteria()
            {
                CampaignId = campaignId,
                CreatedById = AuthorizationService.CurrentUserId.Value,
                IsModified = false
            }))
            {
                throw new InvalidOperationException("Only one comment can be made per user, per campaign");
            }

            var campaign = await PromotionCampaignRepository.ReadDetailsAsync(campaignId);

            if (campaign.Subject.Id == AuthorizationService.CurrentUserId)
            {
                throw new InvalidOperationException("You aren't allowed to comment on your own campaign");
            }

            if (!(campaign.CloseAction is null))
            {
                throw new InvalidOperationException($"Campaign {campaignId} has already been closed");
            }

            var rankRoles = await GetRankRolesAsync(AuthorizationService.CurrentGuildId.Value);

            if (!await CheckIfUserIsRankOrHigherAsync(rankRoles, AuthorizationService.CurrentUserId.Value, campaign.TargetRole.Id))
            {
                throw new InvalidOperationException($"Commenting on a promotion campaign requires a rank at least as high as the proposed target rank");
            }

            PromotionActionSummary resultAction;

            using (var transaction = await PromotionCommentRepository.BeginCreateTransactionAsync())
            {
                resultAction = await PromotionCommentRepository.CreateAsync(new PromotionCommentCreationData()
                {
                    GuildId     = campaign.GuildId,
                    CampaignId  = campaignId,
                    Sentiment   = sentiment,
                    Content     = content,
                    CreatedById = AuthorizationService.CurrentUserId.Value
                });

                transaction.Commit();
            }

            PublishActionNotificationAsync(resultAction);
        }
コード例 #5
0
        public async Task CommentAsync(
            [Summary("The ID value of the campaign to be commented upon")]
            long campaignId,
            [Summary("The sentiment of the comment")]
            PromotionSentiment sentiment,
            [Remainder]
            [Summary("The content of the comment")]
            string content)
        {
            await PromotionsService.AddCommentAsync(campaignId, sentiment, content);

            await Context.AddConfirmation();
        }
コード例 #6
0
        /// <inheritdoc />
        public async Task AddCommentAsync(long campaignId, PromotionSentiment sentiment, string content)
        {
            AuthorizationService.RequireClaims(AuthorizationClaim.PromotionsComment);

            if (content == null || content.Length <= 3)
            {
                throw new InvalidOperationException("Comment content must be longer than 3 characters.");
            }

            using (var transaction = await PromotionCommentRepository.BeginCreateTransactionAsync())
            {
                if (await PromotionCommentRepository.AnyAsync(new PromotionCommentSearchCriteria()
                {
                    CampaignId = campaignId,
                    CreatedById = AuthorizationService.CurrentUserId.Value
                }))
                {
                    throw new InvalidOperationException("Only one comment can be made per user, per campaign");
                }

                var campaign = await PromotionCampaignRepository.ReadDetailsAsync(campaignId);

                if (!(campaign.CloseAction is null))
                {
                    throw new InvalidOperationException($"Campaign {campaignId} has already been closed");
                }

                var rankRoles = await GetRankRolesAsync(AuthorizationService.CurrentGuildId.Value);

                if (!await CheckIfUserIsRankOrHigher(rankRoles, AuthorizationService.CurrentUserId.Value, campaign.TargetRole.Id))
                {
                    throw new InvalidOperationException($"Commenting on a promotion campaign requires a rank at least as high as the proposed target rank");
                }

                await PromotionCommentRepository.CreateAsync(new PromotionCommentCreationData()
                {
                    GuildId     = campaign.GuildId,
                    CampaignId  = campaignId,
                    Sentiment   = sentiment,
                    Content     = content,
                    CreatedById = AuthorizationService.CurrentUserId.Value
                });

                transaction.Commit();
            }
        }
コード例 #7
0
ファイル: PromotionService.cs プロジェクト: TAGC/MODiX
        public async Task AddComment(PromotionCampaignEntity campaign, string comment, PromotionSentiment sentiment)
        {
            comment = _badCharacterRegex.Replace(comment, "");

            if (comment.Trim().Length < 10)
            {
                throw new ArgumentException("Comment is too short, must be more than 10 characters.");
            }

            if (comment.Length > 1000)
            {
                throw new ArgumentException("Comment is too long, must be under 1000 characters.");
            }

            if (campaign.Status != CampaignStatus.Active)
            {
                throw new ArgumentException("Campaign must be active to comment.");
            }

            var promotionComment = new PromotionCommentEntity
            {
                PostedDate = DateTimeOffset.UtcNow,
                Body       = comment,
                Sentiment  = sentiment
            };

            await _repository.AddCommentToCampaign(campaign, promotionComment);
        }