Exemplo n.º 1
0
        public void AddVoucher(string voucherCode, HttpContextBase httpContext)
        {
            Basket basket = GetBasket(httpContext);
            Voucher voucher = vouchers.GetAll().FirstOrDefault(v => v.VoucherCode == voucherCode);

            if (voucher != null)
            {
                VoucherType voucherType = voucherTypes.GetById(voucher.VoucherTypeId);
                if (voucherType != null)
                {
                    BasketVoucher basketVoucher = new BasketVoucher();
                    if (voucherType.Type == "MoneyOff")
                    {
                        MoneyOff(voucher, basket, basketVoucher);
                    }
                    if (voucherType.Type == "PercentOff")
                    {
                        PercentOff(voucher, basket, basketVoucher);
                    }

                    baskets.Commit();
                }
            }
        }
Exemplo n.º 2
0
 public void PercentOff(Voucher voucher, Basket basket, BasketVoucher basketVoucher)
 {
     if (voucher.MinSpend > basket.BasketTotal())
     {
         basketVoucher.Value = (voucher.Value * (basket.BasketTotal() / 100)) * -1;
         basketVoucher.VoucherCode = voucher.VoucherCode;
         basketVoucher.VoucherDescription = voucher.VoucherDescription;
         basketVoucher.VoucherId = voucher.VoucherId;
         basket.AddBasketVoucher(basketVoucher);
     }
 }
Exemplo n.º 3
0
 public void MoneyOff(Voucher voucher, Basket basket, BasketVoucher basketVoucher)
 {
     decimal basketTotal = basket.BasketTotal();
     if (voucher.MinSpend <= basketTotal)
     {
         basketVoucher.Value = voucher.Value * -1;
         basketVoucher.VoucherCode = voucher.VoucherCode;
         basketVoucher.VoucherDescription = voucher.VoucherDescription;
         basketVoucher.VoucherId = voucher.VoucherId;
         basket.AddBasketVoucher(basketVoucher);
     }
 }