public static IBasketTotalCalculator GetBasketTotalCalculator(IBasketTotalCalculator basketTotalCalculator)
        {
            basketTotalCalculator = new BuyTwoItemsGetDiscountDecorator("Butter", "Bread", basketTotalCalculator);
            basketTotalCalculator = new BuyThreeItemsGetFourthItemFreeDecorator("Milk", basketTotalCalculator);

            return(basketTotalCalculator);
        }
        public ActionResult Index(HomeIndexViewModel viewModel)
        {
            var basketItems = from p in viewModel.Products
                              select new BasketItem
            {
                Name     = p.ProductName,
                Cost     = p.ProductPrice,
                Quantity = p.Quantity
            };

            foreach (var item in basketItems)
            {
                _basket.AddBasketItem(item);
            }

            IBasketTotalCalculator basketTotalCalculator = _basket;

            basketTotalCalculator = BasketTotalCalculatorFactory.GetBasketTotalCalculator(basketTotalCalculator);

            viewModel.BasketTotal = basketTotalCalculator.CalculateBasketTotal();

            return(View(viewModel));
        }
 public BuyTwoItemsGetDiscountDecorator(string sourceItem, string targetItem, IBasketTotalCalculator basketTotalCalculator)
     : base(basketTotalCalculator)
 {
     this._sourceItem = sourceItem;
     this._targetItem = targetItem;
 }
Example #4
0
 public BasketTotalDecorator(IBasketTotalCalculator basketTotalCalculator)
 {
     _basketTotalCalculator = basketTotalCalculator;
 }
Example #5
0
 public BuyThreeItemsGetFourthItemFreeDecorator(string item, IBasketTotalCalculator basketTotalCalculator)
     : base(basketTotalCalculator)
 {
     this._item = item;
 }