コード例 #1
0
        public OrderProcessingViewModel ProcessOrderBeforePayment(ShoppingCartViewModel cart, CheckoutInputModel checkout)
        {
            var response = new OrderProcessingViewModel();
            
            // 1. Save checkout data as part of the customer record (shipping & payment).
            //    This is a bit simplistic as shipping address and payment details should be both on Customer
            //    (to set default options) and Order (to be part of the history).
            var address = Address.Create(checkout.Address, "", checkout.City, "", checkout.Country);
            var payment = CreditCard.Create(checkout.CardType, checkout.CardNumber, "", new ExpiryDate(checkout.Month, checkout.Year));
            _requestService.SaveCheckoutInformation(cart.OrderRequest, address, payment);


            // 2. Goods in store (precheck to give users a chance not to place an order that may take a while to 
            //    be completed and served. Most sites just make you pay and place an order for missing items while
            //    giving you a chance to cancel the order at any time.
            var stock = _requestService.CheckStockLevelForOrderedItems(cart.OrderRequest);
            if (stock.Insufficient.Any())
            {
                response.Denied = true;
                response.AddMessage("It seems that we don't have available all the items you ordered. What would you like to do? Buying a bit less or trying later?");
                return response;
            }

            // 3. Payment history for the customer
            //    Probably not really an appropriate scenario for this simple store: if the online store accept
            //    payment cash-on-delivery, however, you might want to enable it only for customers with a
            //    positive payment history.
            if (!_requestService.CheckCustomerPaymentHistory(cart.OrderRequest.Buyer.CustomerId))
            {
                response.Denied = true;
                response.AddMessage("We've found something incorrect in your record that prevents our system from processing your order. Please, contact our customer care.");
                return response;
            }

            // 4. Refill stock
            var productsToOrder = new List<Product>();
            productsToOrder.AddRange(stock.Low);
            productsToOrder.AddRange(stock.Insufficient);
            _requestService.RefillStoreForProduct(productsToOrder);

            return response;
        }
コード例 #2
0
 public ProcessOrderBeforePaymentCommand(ShoppingCartViewModel cart, CheckoutInputModel checkout)
 {
     ShoppingCart = cart;
     CheckoutData = checkout;
 }
コード例 #3
0
 public ShoppingCartViewModel AddProductToShoppingCart(ShoppingCartViewModel cart, int productId, int quantity)
 {
     var product = (from p in cart.Products where p.Id == productId select p).First();
     cart.OrderRequest.AddItem(quantity, product);
     return cart;
 }
コード例 #4
0
 public ProcessOrderAfterPaymentCommand(ShoppingCartViewModel cart, string transactionId)
 {
     ShoppingCart = cart;
     TransactionId = transactionId;
 }
コード例 #5
0
        public OrderProcessedViewModel ProcessOrderAfterPayment(ShoppingCartViewModel cart, string transactionId)
        {
            // 1. Create order ID
            var tempOrderId = _requestService.GenerateTemporaryOrderId();

            // 2. Register order in the system 
            var order = Domain.Orders.Order.CreateFromShoppingCart(tempOrderId, cart.OrderRequest);
            var orderId = _orderRepository.AddAndReturnKey(order);

            // 3. Ship 
            var shipmentDetails = _shipmentService.SendRequestForDelivery(order);

            // 4. Update fidelity card and membership status

            // Prepare model
            var model = new OrderProcessedViewModel
            {
                OrderId = orderId.ToString(CultureInfo.InvariantCulture),
                PaymentDetails = {TransactionId = transactionId},
                ShippingDetails = shipmentDetails
            };
            return model;
        }
コード例 #6
0
ファイル: OrderController.cs プロジェクト: ljvblfz/NAAE
 private void SaveCurrentShoppingCart(ShoppingCartViewModel cart)
 {
     var customerId = User.Identity.Name;
     var cartName = GetShoppingCartName(customerId); 
     Session[cartName] = cart;
 }
コード例 #7
0
 public static ShoppingCartViewModel CreateEmpty(ShoppingCart cart, ICollection<Product> products)
 {
     var model = new ShoppingCartViewModel {OrderRequest = cart, Products = products};
     return model;
 }