コード例 #1
0
        public async Task <IActionResult> Index(CheckoutViewModel checkoutViewModel)
        {
            if (ModelState.IsValid)
            {
                List <ProductOrder> productOrders = new List <ProductOrder>();
                checkoutViewModel.Cart.CartMembers.ForEach(cm =>
                {
                    productOrders.Add(new ProductOrder {
                        Product = productRepository.GetProductById(cm.ProductId), Quantity = cm.Count
                    }
                                      );
                });

                string userId = await GetCurrentUserIdAsync();

                Order order = new Order(productOrders,
                                        checkoutViewModel.Cart.Total, userId);

                await orderProcessor.ProcessAsync(order, $"{Request.Scheme}://{Request.Host}{Request.PathBase}");

                ControllerContext.HttpContext?.Session.Remove(Cart.SessionKey);
                TempData["msg"] = "Your order has been placed! You will receive an email message with details.";
                return(RedirectToAction("Index", "Order", null));
            }
            else
            {
                return(View(checkoutViewModel));
            }
        }
コード例 #2
0
        //Converts a message (for instance from a message queue) into an order, and starts the orderflow
        public async Task HandleMessage(Message message)
        {
            var order = new Order()
            {
                FullName     = message.FullName,
                EmailAddress = message.Emailaddress,
                Basket       = message.Basket.Select(itemId => new BasketItem()
                {
                    ItemId = itemId
                }).ToArray()
            };

            await _orderProcessor.ProcessAsync(order);
        }