예제 #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);
            }
        }
예제 #2
0
        public async Task Consume(ReceiveContext <ReceivableBooked> messageContext)
        {
            var @event             = messageContext.Message;
            var orderStatusRequest = new GetOrderStatus(@event.OrderStatus);
            var orderStatus        = await this.requestBus.Request <GetOrderStatus, OrderStatus>(orderStatusRequest);

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

            await this.uow.Save();

            var response = new OrderStatusResponse(orderStatus.LongDescription);
            await messageContext.Respond(response);
        }
예제 #3
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);
            }
        }