コード例 #1
0
        public PurchaseInvoice CreateInvoice(ShoppingBasket basket, string customerInfo)
        {
            var invoice = new PurchaseInvoice();
            var items   = basket.GetItems();

            foreach (var item in items)
            {
                invoice.totalAmount += item.ItemPrice * item.Quantity;
            }

            // apply discount
            if (items.Count > 5)
            {
                invoice.discount = 20;
            }

            invoice.netTotal = invoice.totalAmount - invoice.discount;
            return(invoice);
        }
コード例 #2
0
        public bool CreateOrder(ShoppingBasket basket, string custInfo)
        {
            // Check stock
            bool      isAvailable = true;
            Inventory inventory   = new Inventory();

            foreach (var item in basket.GetItems())
            {
                if (!inventory.CheckItemQuantity(item.ItemId, item.Quantity))
                {
                    isAvailable = false;
                }
            }

            if (isAvailable)
            {
                // Create Inventory Order
                InventoryOrder inventoryOrder = new InventoryOrder();
                inventoryOrder.CreateOrder(basket, "123");

                // Create Invoice
                PurchaseInvoice invoice = new PurchaseInvoice();
                var             inv     = invoice.CreateInvoice(basket, "address:123,id=6546,email=xyz");

                // Payment
                PaymentProcessor payment = new PaymentProcessor();
                payment.HandlePayment(inv.netTotal, "acc=123456879");

                // Send SMS
                SmsNotofications sms = new SmsNotofications();
                sms.SendSms("132", "Invoice Created");

                return(true);
            }
            else
            {
                return(false);
            }
        }