Exemple #1
0
        private async Task OrderPaymentFailed(OrderModel order, string v)
        {
            // Persist order
            var orderDataService = ServiceProxyUtils.GetOrderService(order.Id);
            var updatedOrder     = order.Clone();

            updatedOrder.State = OrderState.Failed;
            updatedOrder.Payment.ProcessingDate = DateTime.UtcNow;
            updatedOrder.Payment.Status         = PaymentStatus.Failed;

            updatedOrder = await orderDataService.Update(updatedOrder);

            // Send to topic "order payment failed"
            await NotifyTopic(this.serviceBusConfiguration.OrderPaymentFailedTopicName, new OrderFinalizedEvent(updatedOrder));
        }
Exemple #2
0
        public async Task <IActionResult> Get(Guid orderId)
        {
            try
            {
                var orderDataService = ServiceProxyUtils.GetOrderService(orderId);
                var order            = await orderDataService.Get(orderId);

                return(order == null ?
                       (IActionResult)this.NotFound() :
                       this.Ok(order));
            }
            catch (AggregateException ex)
            {
                if (ex.InnerException is OrderNotFoundException)
                {
                    return(this.NotFound());
                }

                throw;
            }
        }
Exemple #3
0
        private void CreateOrderHandler(BrokeredMessage message)
        {
            try
            {
                var command = message.GetBody <CreateOrderCommand>();

                var order = new OrderModel()
                {
                    Id              = command.OrderId,
                    CreationDate    = DateTime.UtcNow,
                    State           = OrderState.Created,
                    Items           = command.Items,
                    DeliveryAddress = command.DeliveryAddress,
                };

                order.Total   = order.Items.Sum(x => x.UnitPrice * x.Price);
                order.Payment = new PaymentModel()
                {
                    CreditCardNumber = command.Payment.CreditCardNumber,
                    CreditCardType   = command.Payment.CreditCardType,
                    ExpirationMonth  = command.Payment.ExpirationMonth,
                    ExpirationYear   = command.Payment.ExpirationYear,
                    Status           = PaymentStatus.Pending,
                    Value            = order.Total,
                };

                // Persist order
                var orderDataService = ServiceProxyUtils.GetOrderService(order.Id);
                var createdOrder     = orderDataService.Create(order);

                // Send to topic "ordercreated"
                NotifyTopic(new OrderCreatedEvent(createdOrder));


                // Send to queue "orderverifyinventory"
            }
            catch (Exception ex)
            {
            }
        }
Exemple #4
0
        private async Task CreateOrderHandler(BrokeredMessage message)
        {
            try
            {
                var command = message.GetJsonBody <CreateOrderCommand>();

                var orderItems = new List <OrderItemModel>();
                foreach (var item in command.Items)
                {
                    var product = await this.catalogProductAPIClient.Get(item.ProductId);

                    if (product == null)
                    {
                        await NotifyTopic(this.serviceBusConfiguration.OrderCreationFailedTopicName, new OrderCreationFailedEvent()
                        {
                            OrderId = command.OrderId,
                            Reason  = $"Product {item.ProductId} not found",
                        });
                    }

                    var orderItem = new OrderItemModel()
                    {
                        ProductId = product.Id,
                        Quantity  = item.Quantity,
                        UnitPrice = product.Price,
                        Price     = product.Price * item.Quantity,
                        VendorId  = product.VendorId
                    };
                    orderItems.Add(orderItem);
                }

                var order = new OrderModel()
                {
                    Id              = command.OrderId,
                    CreationDate    = DateTime.UtcNow,
                    State           = OrderState.Created,
                    Items           = orderItems,
                    DeliveryAddress = command.DeliveryAddress,
                };

                order.Total   = order.Items.Sum(x => x.Price);
                order.Payment = new PaymentModel()
                {
                    CreditCardNumber = command.Payment.CreditCardNumber,
                    CreditCardType   = command.Payment.CreditCardType,
                    ExpirationMonth  = command.Payment.ExpirationMonth,
                    ExpirationYear   = command.Payment.ExpirationYear,
                    Status           = PaymentStatus.Pending,
                    Value            = order.Total,
                };

                // Persist order
                var orderDataService = ServiceProxyUtils.GetOrderService(order.Id);
                var createdOrder     = await orderDataService.Create(order);

                // Send to topic "ordercreated"
                await NotifyTopic(this.serviceBusConfiguration.OrderCreatedTopicName, new OrderCreatedEvent(createdOrder));

                // Send to queue "orderverifypayment"
                await SendCommand(this.serviceBusConfiguration.VerifyOrderPaymentQueueName, new VerifyOrderPaymentCommand(createdOrder));
            }
            catch (Exception ex)
            {
                await message.AbandonAsync();
            }
        }