示例#1
0
        public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails, Order order)
        {
            if (!cart.Lines.Any())
            {
                ModelState.AddModelError("", @"Sorry, your cart is empty!");
            }

            if (ModelState.IsValid)
            {
                _orderProcessor.SendEmail(cart, shippingDetails);
                _orderProcessor.CreateOrder(cart, shippingDetails, order);

                foreach (var line in cart.Lines)
                {
                    foreach (var product in _productRepository.Products)
                    {
                        if (product.ProductId == line.Product.ProductId)
                        {
                            product.Quantity -= line.Quantity;
                        }
                    }
                }
                _productRepository.UpdateProduct();
                _logger.Info($"Order №{order.OrderId} was created.");
                cart.Clear();
                return(View("Completed"));
            }
            return(View(shippingDetails));
        }
示例#2
0
        public void Process(Cart cart, ShippingDetails shippingDetails)
        {
            var order = ProcessTheOrder(cart, shippingDetails);

            orderRepository.CreateOrder(order);
            cart.Clear();
        }