Exemplo n.º 1
0
        public void PostComment(Comment comment)
        {
            CheckIfCreated();
            CheckIfDeleted();

            if (!comment.Author.Approved && !(comment.Author.Id == ProjectOwner.Id))
            {
                throw new ArgumentException("Comment author not approved to post in team chat.");
            }

            var payload     = new { Id = comment.Id, AuthorId = comment.Author.Id, Content = comment.Content, PostedOn = comment.PostedOn };
            var jsonPayload = JsonConvert.SerializeObject(payload);

            var teamCommentPostedEvent = new TeamCommentPostedEvent(
                Id,
                Version + 1,
                jsonPayload);

            Apply(teamCommentPostedEvent);
        }
Exemplo n.º 2
0
        public void Handle(TeamCommentPostedEvent domainEvent)
        {
            LogToConsole(domainEvent);

            dynamic eventData = JsonConvert.DeserializeObject(domainEvent.JsonPayload);

            var     query = new GetUserQuery((Guid)eventData.AuthorId);
            dynamic user  = JsonConvert.DeserializeObject(_bus.PublishQuery(query));

            //TODO: add usernames.
            var newComment = new Comment
            {
                TeamId     = domainEvent.AggregateId,
                AuthorId   = (Guid)eventData.AuthorId,
                AuthorName = (string)user.UserName,
                PostedOn   = (DateTime)eventData.PostedOn,
                Content    = (string)eventData.Content
            };

            _commentRepository.Add(newComment);
        }