Esempio n. 1
0
    public decimal CalculateDiscount()
    {
        DiscountDA discount = new DiscountDA();

        List <string>  cakeNames    = new List <string>();
        List <decimal> cakeDiscount = new List <decimal>();

        cakeNames    = discount.getDiscountCakeName();   //get discount cakes from DA -working? -b
        cakeDiscount = discount.getDiscountCakeAmount(); //get discount amounts from DA -working? -b

        //accumulator for amount of discounts for all cakes
        decimal amountOfDiscount = 0;

        for (int x = 0; x < CartList.Count; x++)//for each item in the cart
        {
            //need to loop through the cakeNames list to see if selectedCakeName matches any of them
            string selectedCakeName = CartList.GetNameOfCake(x);
            int    counter          = 0;
            while (counter < cakeNames.Count)
            {
                if (selectedCakeName == cakeNames[counter]) //if the cake names match
                {
                    //get the discount amount out of the list
                    decimal discountAmount = cakeDiscount[counter];
                    //set new cake price with discount
                    amountOfDiscount += CartList.ApplyCakeDiscount(discountAmount, x);
                    //exit loop if it matches and test the next cake
                    counter = cakeNames.Count;
                }
                else
                {
                    counter++;
                }
            }
        }

        //int quantity = CartList.GetQuantity();
        //Subtotal = 0;
        //Subtotal = CartList.GetSubtotal();

        return(amountOfDiscount);
    }