private void Handle(CommentAddedEvent commentAddedEvent, string eventDataJson, EventModel @event, EventMetaData eventMetaData)
        {
            _logger.LogInformation($"Handling {nameof(CommentAddedEvent)} .... {Environment.NewLine} {eventDataJson}");

            _operation          = DatabaseOperation.Update;
            _currentValueRecord = GetRecord(commentAddedEvent.ParentId);

            ThrowIfRecordIsNull(commentAddedEvent, _currentValueRecord);

            if (_currentValueRecord.Comments == null)
            {
                _currentValueRecord.Comments = new List <ValueCommentRecord>();
            }

            _currentValueRecord.Comments.Add(new ValueCommentRecord
            {
                PublicId       = commentAddedEvent.Id,
                ParentId       = commentAddedEvent.ParentId,
                CommentText    = commentAddedEvent.CommentText,
                UserName       = commentAddedEvent.UserName,
                Likes          = commentAddedEvent.Likes,
                Dislikes       = commentAddedEvent.Dislikes,
                CreatedOn      = DateTime.Now,
                LastModifiedOn = DateTime.Now,
                Id             = ObjectId.GenerateNewId()
            });

            UpdateCommonFields(@event, eventMetaData);
        }
Exemple #2
0
        public void Handle(CommentAddedEvent @event)
        {
            var model = new ValueCommentAggregateChildDataModel
            {
                CommentText = @event.CommentText,
                UserName    = @event.UserName,
                TenantId    = @event.TenantId,
                Id          = @event.Id
            };

            var comment = this.AddComment(model, applyEvent: false);

            this.Comments.Add(comment);
        }
Exemple #3
0
        public void AddComment(int articleId, m_ArticleComment comment)
        {
            var article = repo.GetAllIncluding(a => a.Comments).Where(a => a.Id == articleId).FirstOrDefault();

            article.Comments.Add(comment);
            uow.Save();

            CommentAddedEvent commentAddedEvent = new CommentAddedEvent()
            {
                Article        = article,
                CurrentComment = comment
            };

            eventBus.Publish(commentAddedEvent);
        }
Exemple #4
0
 /// <summary>
 /// Fires when comment has been added to an article.
 /// </summary>
 /// <param name="e">Comment added event payload.</param>
 /// <returns>Async Task.</returns>
 public async Task OnCommentAddedAsync(CommentAddedEvent e)
 {
     await this.Clients.All.SendAsync("CommentAddedEvent", e);
 }