Ejemplo n.º 1
0
        /// <summary>
        /// Calculates the Price.
        /// </summary>
        /// <param name="item">The item to calculate the price for.</param>
        /// <param name="itemQty">The item quantity.</param>
        /// <returns>The calculated price.</returns>
        public decimal Calculate(Item item, int itemQty)
        {
            decimal totalPrice      = 0;
            int     tempQty         = itemQty;
            int     specialOfferQty = _kataItemsDatabaseAccess.GetItemSpecialOfferQty(item.Sku);

            while (tempQty > 0)
            {
                if (tempQty >= specialOfferQty)
                {
                    totalPrice += _kataItemsDatabaseAccess.GetSpecialOfferPrice(item.Sku);
                    tempQty    -= specialOfferQty;
                }
                else
                {
                    decimal unitPrice = _kataItemsDatabaseAccess.GetUnitPrice(item.Sku);

                    unitPrice  *= tempQty;
                    totalPrice += unitPrice;
                    tempQty     = 0;
                }
            }

            return(totalPrice);
        }