Example #1
0
        public void Handle(CommentPosted @event)
        {
            // Update the message count first
            // As this is an update of an existing conversation, load the existing conversation
            ConversationSummaryEntity conversationSummary = ConversationSummaryRepository.Load(@event.ConversationRsn);

            // Update the message count from the aggregate
            conversationSummary.MessageCount    = @event.CurrentMessageCount;
            conversationSummary.LastUpdatedDate = @event.DatePosted;
            // As this is an update of an existing conversation, pass the updated entity to the Repository to be updated and persisted
            ConversationSummaryRepository.Update(conversationSummary);

            MessageEntity messageEntity = new MessageEntity
            {
                Rsn              = @event.MessageRsn,
                ConversationRsn  = @event.ConversationRsn,
                ConversationName = @event.ConversationName,
                UserRsn          = @event.UserRsn,
                UserName         = @event.UserName,
                Content          = @event.Comment,
                DatePosted       = @event.DatePosted
            };

            // As this is the creation of a new comment, pass the entity to the Repository for creation and persisted
            MessageRepository.Create(messageEntity);
        }
Example #2
0
        public void Handle(ConversationUpdated @event)
        {
            // As this is an update of an existing conversation, load the existing conversation
            ConversationSummaryEntity conversationSummary = ConversationSummaryRepository.Load(@event.Rsn);

            // Update the name
            conversationSummary.Name = @event.Name;
            // As this is an update of an existing conversation, pass the updated entity to the Repository to be updated and persisted
            ConversationSummaryRepository.Update(conversationSummary);

            // Update all message projections
            // Define Query
            ICollectionResultQuery <MessageQueryStrategy, MessageEntity> query = QueryFactory.CreateNewCollectionResultQuery <MessageQueryStrategy, MessageEntity>();

            query.QueryStrategy.WithConversationRsn(@event.Rsn);
            query.QueryStrategy.OrderByDatePosted();

            // Retrieve Data
            query = MessageRepository.Retrieve(query);

            foreach (MessageEntity messageEntity in query.Result)
            {
                // Update the name
                messageEntity.ConversationName = @event.Name;

                // As this is an update of an existing message, pass the updated entity to the Repository to be updated and persisted
                MessageRepository.Update(messageEntity);
            }
        }
        public void Handle(ConversationDeleted @event)
        {
            // As this is a delete of an existing conversation, load the existing conversation
            ConversationSummaryEntity conversationSummary = ConversationSummaryRepository.Load(@event.Rsn);

            // This will logically delete the conversation so it can be retrieved in a list of deleted conversations to be un-deleted.
            ConversationSummaryRepository.Delete(conversationSummary);

            // Update all message projections
            // Define Query
            ICollectionResultQuery <MessageQueryStrategy, MessageEntity> query = QueryFactory.CreateNewCollectionResultQuery <MessageQueryStrategy, MessageEntity>();

            query.QueryStrategy.WithConversationRsn(@event.Rsn);
            query.QueryStrategy.OrderByDatePosted();

            // Retrieve Data
            query = MessageRepository.Retrieve(query);

            foreach (MessageEntity messageEntity in query.Result)
            {
                // This will logically delete the message so it can be retrieved in a list of deleted messages to be un-deleted.
                MessageRepository.Delete(messageEntity);
            }
        }