Exemplo n.º 1
0
        public virtual async Task Consume(ReceiveContext <OrderItemAdded> messageContext)
        {
            var message     = messageContext.Message;
            var orderStatus = await this.GetOrderStatus(message.OrderStatus);

            this.uow.Update <OrderReview>()
            .SetReference(o => o.OrderTotal, message.OrderTotal)
            .SetValue(o => o.OrderStatusDescription, orderStatus.Description)
            .Where(o => o.Id, message.OrderId);

            var request = new GetProduct(message.OrderItem.ProductId);
            var product = await this.requestBus.Request <GetProduct, Product>(request);

            var item = new OrderItem(
                message.OrderId,
                message.OrderItem.LineNumber,
                product.Name,
                message.OrderItem.Quantity,
                message.OrderItem.Price);

            this.uow.Add(item);

            await this.uow.Save();

            if (message.OrderStatus == OrderStatusEnum.OrderSuspended)
            {
                var response = new OrderStatusResponse(orderStatus.LongDescription);
                await messageContext.Respond(response);
            }
        }
Exemplo n.º 2
0
        public virtual async Task Consume(ReceiveContext <OrderCreated> messageContext)
        {
            var message         = messageContext.Message;
            var customerRequest = new GetCustomer(message.CustomerId);
            var customer        = await this.requestBus.Request <GetCustomer, Customer>(customerRequest);

            var orderStatus = await this.GetOrderStatus(message.OrderStatus);

            var orderReview = new OrderReview(
                message.OrderId,
                customer.Name,
                message.OrderTotal,
                orderStatus.Description);

            this.uow.Add(orderReview);

            foreach (var eventItem in message.Items)
            {
                var productRequest = new GetProduct(eventItem.ProductId);
                var product        = await this.requestBus.Request <GetProduct, Product>(productRequest);

                var item = new OrderItem(
                    message.OrderId,
                    eventItem.LineNumber,
                    product.Name,
                    eventItem.Quantity,
                    eventItem.Price);
                this.uow.Add(item);
            }

            await this.uow.Save();

            if (message.OrderStatus == OrderStatusEnum.OrderSuspended)
            {
                var response = new OrderStatusResponse(orderStatus.LongDescription);
                await messageContext.Respond(response);
            }
        }