예제 #1
0
        public static Output ShoppingBasketToOutput(ShoppingBasket shoppingBasket, int count)
        {
            Output output = new Output();

            output.Header = "Output " + count + ":";

            double totalPrice = 0.00;
            double totalTax   = 0.00;

            foreach (CartItem cartItem in shoppingBasket.CartItems)
            {
                string itemName       = cartItem.Imported ? "imported " + cartItem.Product.Name : cartItem.Product.Name;
                double totalItemPrice = cartItem.Price + cartItem.SalesTax;
                totalPrice += totalItemPrice;
                totalTax   += cartItem.SalesTax;
                string item = cartItem.Quantity + " " + itemName + ": " + string.Format("{0:N2}", totalItemPrice);
                output.Items.Add(item);
            }
            output.Total    = "Total: " + string.Format("{0:N2}", totalPrice);
            output.SalesTax = "Sales Taxes: " + string.Format("{0:N2}", totalTax);

            return(output);
        }