示例#1
0
        /// <summary>
        /// Calculates the total cost of an order.
        /// </summary>
        /// <param name="orderId">The unique identifier of the order.</param>
        /// <returns>The total cost of the order.</returns>
        public double CalculateOrderTotal(int orderId)
        {
            var coffees = _coffeeRepository.GetByOrderId(orderId);

            if (!coffees.Any())
            {
                throw new ArgumentOutOfRangeException("There is no coffee added to the order. Please add coffee before attempting to purchase your order.");
            }

            var totalSmalls  = coffees.Count(c => c.Size == "small");
            var totalMediums = coffees.Count(c => c.Size == "medium");
            var totalLarges  = coffees.Count(c => c.Size == "large");

            var totalCream = coffees.Sum(c => c.AmountOfCream);
            var totalSugar = coffees.Sum(c => c.AmountOfSugar);

            return(totalSmalls * CostOfSmallCoffee + totalMediums * CostOfMediumCoffee + totalLarges * CostOfLargeCoffee + totalCream * CostOfCream + totalSugar * CostOfSugar);
        }