Ejemplo n.º 1
0
    public decimal CalculateDiscount(CartItemList cart)
    {
        DiscountDA discount = new DiscountDA();

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

        cakeNames    = discount.getDiscountCakeName();
        cakeDiscount = discount.getDiscountCakeAmount();

        decimal amountOfDiscount = 0;

        for (int x = 0; x < cart.Count; x++)
        {
            string selectedCakeName = cart.GetNameOfCake(x);
            int    counter          = 0;
            while (counter < cakeNames.Count)
            {
                if (selectedCakeName == cakeNames[counter])
                {
                    decimal discountAmount = cakeDiscount[counter];
                    amountOfDiscount += cart.DiscountAmountForSummary(discountAmount, x);
                    counter           = cakeNames.Count;
                }
                else
                {
                    counter++;
                }
            }
        }
        return(amountOfDiscount);
    }
Ejemplo n.º 2
0
 public TicketBL()
 {
     dataAccess      = new TicketDA();
     productDA       = new ProductDA();
     naturalClientDA = new NaturalClientDA();
     legalClientDA   = new LegalClientDA();
     discountDA      = new DiscountDA();
 }
Ejemplo n.º 3
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);
    }