Example #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 (voucher != null)
                {
                    BasketVoucher basketVoucher = new BasketVoucher();

                    try
                    {
                        // modulen måste aktiveras igenom att använda de fullständiga namnet av classen o innhållande projekt
                        // alltså : fullständiga namnet av klassen ska innehålla namespace ->
                        // alltså : eCommerce.Modules.Vouchers.MoneyOff.eVoucher,eCommerce.Modules.Vouchers.MoneyOff

                        IeVoucher voucherProcessor = Activator.CreateInstance(Type.GetType(voucherType.VoucherModule)) as IeVoucher;
                        voucherProcessor.ProcessVoucher(voucher, basket, basketVoucher);
                    }
                    catch (Exception ex)
                    {
                        basketVoucher.VoucherDescription = ex.ToString();
                    }

                    baskets.Commit();
                }
            }
        }
Example #2
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();
                    try
                    {
                        IeVoucher voucherProcessor = Activator.CreateInstance(Type.GetType(voucherType.VoucherModule)) as IeVoucher;
                        voucherProcessor.ProcessVoucher(voucher, basket, basketVoucher);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    //BasketVoucher basketVoucher = new BasketVoucher();
                    //if (voucherType.Type == "MoneyOff")
                    //{
                    //    MoneyOff(voucher, basket, basketVoucher);
                    //}
                    //if (voucherType.Type == "PercentOff")
                    //{
                    //    PercentOff(voucher, basket, basketVoucher);
                    //}
                    baskets.Commit();
                }
            }
        }
Example #3
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();
                    //implements without modules
                    //if (voucherType.Type == "MoneyOff")
                    //{
                    //    MoneyOff(voucher, basket, basketVoucher);
                    //}
                    //if (voucherType.Type == "PercentOff")
                    //{
                    //    PercentOff(voucher, basket, basketVoucher);
                    //}
                    //_basbaskets.Commit();
                    //implements modules
                    try
                    {
                        //Modules must be activated using full name of the class and containing project name e.g.
                        //<full name of class including namespace>,<full name of namespace> e.g
                        //eCommerce.Modules.Vouchers.MoneyOff.eVoucher, eCommerce.Modules.Vouchers.MoneyOff
                        //eCommerce.Modules.Vouchers.PercentOff.eVoucher, eCommerce.Modules.Vouchers.PercentOff
                        IeVoucher voucherProcessor =
                            Activator.CreateInstance(Type.GetType(voucherType.VoucherModule)) as IeVoucher;
                        voucherProcessor?.ProcessVoucher(voucher, basket, basketVoucher);
                        _basbaskets.Commit();
                    }
                    catch (Exception exception)
                    {
                        //log an error
                    }
                }
            }
        }
        public void AddBasketVoucher(string vc, HttpContextBase httpContext)
        {
            Basket  bkt        = FetchBasket(httpContext);
            Voucher theVoucher = vouchers.GetAll().FirstOrDefault(v => v.VoucherCode == vc);

            if (theVoucher != null)
            {
                VoucherType vt = voucherTypes.GetById(theVoucher.VoucherId);
                if (vt != null)
                {
                    BasketVoucher bv = new BasketVoucher();
                    //if (vt.Type == "MoneyOff")
                    //{
                    //    MoneyOff(theVoucher, bkt, bv);
                    //}
                    //if (vt.Type == "PercentOff")
                    //{
                    //    PercentOff(theVoucher, bkt, bv);
                    //}
                    try
                    {
                        IeVoucher VoucherProcess = Activator.CreateInstance(Type.GetType(vt.VoucherModule)) as IeVoucher;
                        VoucherProcess.ProcessVoucher(theVoucher, bkt, bv);

                        baskets.Commit();
                    }
                    catch (Exception ex)
                    {
                        throw new System.Exception(ex.ToString());
                    }
                }
            }
            else
            {
                return;
            }
        }