Beispiel #1
0
        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);
        }