internal static PromotionCommentMutationData FromEntity(PromotionCommentEntity entity)
 => new PromotionCommentMutationData
 {
     CampaignId = entity.CampaignId,
     Sentiment  = entity.Sentiment,
     Content    = entity.Content,
 };
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public async Task AddCommentToCampaign(PromotionCampaignEntity campaign, PromotionCommentEntity comment)
        {
            await campaign.Comments.AddAsync(comment);

            await _context.SaveChangesAsync();
        }