Esempio n. 1
0
 private void ProcessPrice(OrderItem orderItem)
 {
     decimal netPrices = orderItem.Item.Price * orderItem.Quantity;
     decimal salesTax = this._taxService.CalculateTax(orderItem.Item.SalesTaxType.ToString(), netPrices);
     decimal dutyTax = this._taxService.CalculateTax(orderItem.Item.DutyTaxType.ToString(), netPrices);
     decimal totalTaxes = decimal.Round(salesTax + dutyTax, 2, MidpointRounding.AwayFromZero);
     decimal totalPrice = netPrices + totalTaxes;
     orderItem.TotalTaxes = totalTaxes;
     orderItem.TotalPrices = totalPrice;
 }
Esempio n. 2
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;
        }