コード例 #1
0
        /// <summary>
        /// This will calculate the total bill for the items in the shopping cart
        /// </summary>
        /// <param name="shoppingCart">list of items added to the shopping cart </param>
        /// <param name="offersExist">true, if any offers available for the products</param>
        /// <returns>total amount</returns>
        private double calculateTotal(List <String> shoppingCart, bool offersExist)
        {
            int total = 0;

            int apples = shoppingCart.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()).Where(x => x.Key == APPLE).FirstOrDefault().Value;

            if (offersExist)
            {
                total += offerServiceFactory.offerFor(APPLE).Apply(apples, APPLE_COST);
            }
            else
            {
                total += _priceCalculation.Apply(apples, APPLE_COST);
            }


            int oranges = shoppingCart.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()).Where(x => x.Key == ORANGE).FirstOrDefault().Value;

            if (offersExist)
            {
                total += offerServiceFactory.offerFor(ORANGE).Apply(oranges, ORANGE_COST);
            }
            else
            {
                total += _priceCalculation.Apply(oranges, ORANGE_COST);
            }

            return(total);
        }
コード例 #2
0
        /// <summary>
        /// This will calculate the total bill for the items in the shopping cart
        /// </summary>
        /// <param name="shoppingCart">list of items added to the shopping cart </param>
        /// <returns>total amount</returns>
        private int calculateTotal(List <String> shoppingCart)
        {
            int total = 0;

            int apples = shoppingCart.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()).Where(x => x.Key == "Apple").FirstOrDefault().Value;

            total += _priceCalculation.Apply(apples, APPLE_COST);

            int oranges = shoppingCart.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()).Where(x => x.Key == "Orange").FirstOrDefault().Value;

            total += _priceCalculation.Apply(oranges, ORANGE_COST);

            return(total);
        }