Ejemplo n.º 1
0
        public void ProcessMessage(IProcessHandlerContext <AcceptOrderProcessCommand> context)
        {
            if (context.Stream.IsEmpty)
            {
                return;
            }

            context.Stream.AddEvent(ChangeStatus("Order Accepted"));

            var command = new CreateOrderCommand
            {
                OrderNumber   = _initialized.OrderNumber,
                OrderDate     = _initialized.DateRegistered,
                CustomerName  = _customerAssigned.CustomerName,
                CustomerEMail = _customerAssigned.CustomerEMail
            };

            foreach (var itemAdded in _items)
            {
                command.Items.Add(new MessageOrderItem
                {
                    Description = itemAdded.Description,
                    Price       = itemAdded.Price
                });
            }

            context.Send(command);

            context.Publish(new OrderProcessAcceptedEvent
            {
                OrderProcessId = CorrelationId
            });
        }
Ejemplo n.º 2
0
        public void ProcessMessage(IProcessHandlerContext <RegisterOrderProcessCommand> context)
        {
            var message = context.Message;

            context.Stream.AddEvent(Initialize());
            context.Stream.AddEvent(AssignCustomer(message.CustomerName, message.CustomerEMail));
            context.Stream.AddEvent(AssignTargetSystem(message.TargetSystem, message.TargetSystemUri));
            context.Stream.AddEvent(ChangeStatus("Cooling Off"));

            foreach (var quotedProduct in message.QuotedProducts)
            {
                context.Stream.AddEvent(
                    AddItem(quotedProduct.ProductId, quotedProduct.Description, quotedProduct.Price));
            }

            context.Publish(new OrderProcessRegisteredEvent
            {
                OrderProcessId  = CorrelationId,
                QuotedProducts  = message.QuotedProducts,
                CustomerName    = message.CustomerName,
                CustomerEMail   = message.CustomerEMail,
                OrderNumber     = _initialized.OrderNumber,
                OrderDate       = _initialized.DateRegistered,
                OrderTotal      = Total,
                Status          = _statusChanged.Status,
                StatusDate      = _statusChanged.StatusDate,
                TargetSystem    = message.TargetSystem,
                TargetSystemUri = message.TargetSystemUri
            });

            context.Send(new AcceptOrderProcessCommand
            {
                OrderProcessId = CorrelationId
            }, c => c.Defer(DateTime.Now.AddSeconds(10)).Local().WithCorrelationId(CorrelationId.ToString("N")));
        }
Ejemplo n.º 3
0
        public void ProcessMessage(IProcessHandlerContext <OrderCreatedEvent> context)
        {
            if (!ShouldProcess(context.TransportMessage, context.Stream))
            {
                return;
            }

            context.Stream.AddEvent(ChangeStatus("Order Created"));
            context.Stream.AddEvent(AssignOrderId(context.Message.OrderId));

            var command = new CreateInvoiceCommand
            {
                OrderId             = _orderIdAssigned.OrderId,
                AccountContactName  = _customerAssigned.CustomerName,
                AccountContactEMail = _customerAssigned.CustomerEMail
            };

            foreach (var item in _items)
            {
                command.Items.Add(new MessageInvoiceItem
                {
                    Description = item.Description,
                    Price       = item.Price
                });
            }

            context.Send(command);
        }
Ejemplo n.º 4
0
        public void ProcessMessage(IProcessHandlerContext <EMailSentEvent> context)
        {
            if (!ShouldProcess(context.TransportMessage, context.Stream))
            {
                return;
            }

            context.Stream.AddEvent(ChangeStatus("Dispatched-EMail Sent"));

            context.Send(new CompleteOrderProcessCommand
            {
                OrderProcessId = CorrelationId
            }, c => c.Local());
        }
Ejemplo n.º 5
0
        public void ProcessMessage(IProcessHandlerContext <InvoiceCreatedEvent> context)
        {
            if (!ShouldProcess(context.TransportMessage, context.Stream))
            {
                return;
            }

            context.Stream.AddEvent(ChangeStatus("Invoice Created"));
            context.Stream.AddEvent(AssignInvoiceId(context.Message.InvoiceId));

            context.Send(new SendEMailCommand
            {
                RecipientEMail = _customerAssigned.CustomerEMail,
                HtmlBody       =
                    string.Format(
                        "Hello {0},<br/><br/>Your order number {1} has been dispatched.<br/><br/>Regards,<br/>The Shuttle Books Team",
                        _customerAssigned.CustomerName, _initialized.OrderNumber)
            });
        }