Example #1
0
        public void ApplyVoucherToCart()
        {
            var customerController = _container.Resolve<CustomerController>();
            var cartController = _container.Resolve<CartController>();

            var customersViewResult = customerController.Index() as ViewResult;

            var model = new ApplyVoucherViewModel()
            {
                CustomerId = ((List<Customer>)customersViewResult.Model)[0].Id,
                VoucherCode = "ABCD"
            };

            var result = cartController.ApplyVoucher(model) as RedirectToRouteResult;
        }
Example #2
0
        public ActionResult ApplyVoucher(ApplyVoucherViewModel model)
        {
            if (!ModelState.IsValid)
                return View(model);

            using (ITransaction transaction = _session.BeginTransaction())
            {
                var cart = _cartRepository.GetCartByCustomerId(model.CustomerId);
                var voucher = _voucherRepository.GetVaucherByCode(model.VoucherCode);

                cart.ApplyVoucher(voucher);

                transaction.Commit();
            }

            return RedirectToAction("Index");
        }