Ejemplo n.º 1
0
        private void CalculateSpendToDiscount(decimal discountableTotal, OfferVoucher voucher)
        {
            decimal spendToOfferValid = voucher.offerThreshold - discountableTotal + 0.01m;

            Console.WriteLine("You have not reached the spend threshold for voucher " + voucher.offerCode
                              + ". Spend Another £" + spendToOfferValid + " to receive £" + voucher.offerValue + " discount from your basket total.");
            Console.WriteLine("Total: £" + basketPrice);
        }
Ejemplo n.º 2
0
 public void Checkout(List <GiftVoucher> giftVouchers, OfferVoucher offerVoucher)
 {
     basketPrice = CalculateBasketPrice();
     OfferVoucherCalculation(offerVoucher);
     if (giftVouchers.Count > 0)
     {
         GiftVoucherCalculation(giftVouchers);
     }
 }
Ejemplo n.º 3
0
        private void OfferVoucherCalculation(OfferVoucher offerVoucher)
        {
            decimal discountablePrice = GetDiscountableProductsPrice();

            if (offerVoucher.offerType.Equals(OfferType.Basket))
            {
                if (discountablePrice >= offerVoucher.offerThreshold)
                {
                    basketPrice = basketPrice - offerVoucher.offerValue;
                    outcomeText = "1 x £" + offerVoucher.offerValue + " off baskets over "
                                  + "£" + offerVoucher.offerThreshold + " Offer Voucher "
                                  + offerVoucher.offerCode + " applied";
                    Console.WriteLine(outcomeText);
                }
                else
                {
                    CalculateSpendToDiscount(discountablePrice, offerVoucher);
                }
            }
            else
            {
                if (basketPrice >= offerVoucher.offerThreshold)
                {
                    decimal discountedPrice = basketPrice;

                    for (int i = 0; i < basketContents.Count; i++)
                    {
                        if (basketContents[i].productCategory.categoryName.Equals(offerVoucher.offerCategory.categoryName))
                        {
                            discountedPrice = basketPrice - basketContents[i].basePrice;
                            outcomeText     = "1 x £" + offerVoucher.offerValue + " off baskets over "
                                              + "£" + offerVoucher.offerThreshold + " Offer Voucher "
                                              + offerVoucher.offerCode + " applied";
                            Console.WriteLine(outcomeText);
                            Console.WriteLine("Total: £" + discountedPrice);
                            break;
                        }
                    }
                    if (discountedPrice.Equals(basketPrice))
                    {
                        outcomeText = "There are no products in your basket applicable to voucher Voucher " + offerVoucher.offerCode;
                        Console.WriteLine(outcomeText);
                    }
                    else
                    {
                        basketPrice = discountedPrice;
                    }
                }
            }
        }