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; }
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); }