Example #1
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);
            }
        }
Example #2
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 #3
0
        /// <summary>
        /// Get all <see cref="ConversationSummaryEntity">conversations</see>.
        /// </summary>
        public virtual IServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> > Get(IServiceRequest <Guid> serviceRequest)
        {
            AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken);
            CorrelationIdHelper.SetCorrelationId(serviceRequest.CorrelationId);

            // Define Query
            ICollectionResultQuery <ConversationSummaryQueryStrategy, ConversationSummaryEntity> query = QueryFactory.CreateNewCollectionResultQuery <ConversationSummaryQueryStrategy, ConversationSummaryEntity>();

            query.QueryStrategy.WithNoDeletedConversations();

            // Retrieve Data
            query = ConversationSummaryRepository.Retrieve(query);
            IEnumerable <ConversationSummaryEntity> queryResults = query.Result;

            var responseData = new ServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> >
            {
                State      = ServiceResponseStateType.Succeeded,
                ResultData = queryResults
            };

            // Complete the response
            ServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> > response = CompleteResponse(responseData);

            return(response);
        }
Example #4
0
        public void Handle(ConversationStarted @event)
        {
            var conversationSummary = new ConversationSummaryEntity
            {
                Rsn             = @event.Rsn,
                Name            = @event.Name,
                LastUpdatedDate = @event.TimeStamp.UtcDateTime,
                MessageCount    = 0
            };

            // As this is the creation of a new conversation, pass the entity to the Repository for creation and persisted
            ConversationSummaryRepository.Create(conversationSummary);
        }
Example #5
0
        public virtual HttpResponseMessage <ServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> > > Get()
        {
            // Define Query
            ICollectionResultQuery <ConversationSummaryQueryStrategy, ConversationSummaryEntity> query = QueryFactory.CreateNewCollectionResultQuery <ConversationSummaryQueryStrategy, ConversationSummaryEntity>();

            query.QueryStrategy.WithNoDeletedConversations();

            // Retrieve Data
            query = ConversationSummaryRepository.Retrieve(query);
            IEnumerable <ConversationSummaryEntity> queryResults = query.Result;

            var responseData = new ServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> >
            {
                State      = ServiceResponseStateType.Succeeded,
                ResultData = queryResults
            };

            // Complete the response
            HttpResponseMessage <ServiceResponseWithResultData <IEnumerable <ConversationSummaryEntity> > > response = CompleteResponseWithData(responseData);

            return(response);
        }
        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);
            }
        }