Ejemplo n.º 1
0
        public Order BuildOrder(IList<Product> products)
        {
            var result = new Order();
            var productGroup = products.GroupBy(product => product.Name);

            foreach (var item in productGroup)
            {
                var orderItem = new OrderItem { Item = item.First(), Quantity = item.Count() };
                this.ProcessPrice(orderItem);
                result.Items.Add(orderItem);
            }

            result.TotalTaxes = result.Items.Sum(item => item.TotalTaxes);
            result.TotalPrices = result.Items.Sum(item => item.TotalPrices);
            return result;
        }
Ejemplo n.º 2
0
        private void Print(Order order)
        {
            Console.WriteLine();

            foreach (var item in order.Items)
            {
                Console.WriteLine("{0} {1} : {2:F2}", item.Quantity, item.Item.Name, item.TotalPrices);
            }

            Console.WriteLine("Sales Taxes: {0:F2}", order.TotalTaxes);
            Console.WriteLine("Total: {0:F2}", order.TotalPrices);
        }