public async Task <IActionResult> Index(Dictionary <string, int> quantities, string couponCode, string action) { try { var user = _appUserParser.Parse(HttpContext.User); var vm = await _basketSvc.GetBasket(user); if (action == "[ Submit Coupon ]") { var updatedBasket = await _couponSvc.Apply(vm, couponCode); await _basketSvc.ApplyCoupon(updatedBasket); } if (action == "[ Update ]") { var basket = await _basketSvc.SetQuantities(user, quantities); } if (action == "[ Checkout ]") { return(RedirectToAction("Create", "Order")); } } catch (Exception ex) { HandleException(ex); } return(View()); }
protected void ApplyCouponButton_Click(object sender, EventArgs e) { if (Page.IsValid) { IBasketService basketService = AbleContext.Resolve <IBasketService>(); CouponResult result = basketService.ApplyCoupon(AbleContext.Current.User.Basket, CouponCode.Text); if (result.ResultType == CouponResultType.Valid) { ValidCouponMessage.Visible = true; ValidCouponMessage.Text = string.Format(ValidCouponMessage.Text, CouponCode.Text); if (result.RemovedCoupons.Count > 0) { CouponsRemovedMessage.Text = String.Format(CouponsRemovedMessage.Text, string.Join(", ", result.RemovedCoupons.ToArray())); CouponsRemovedMessage.Visible = true; } CouponAppliedHandler(this, e); } else { // handle error switch (result.ResultType) { case CouponResultType.InvalidCode: InvalidCouponMessage.Text = "<p class=\"error\">The coupon code you entered is invalid.</p>"; break; case CouponResultType.AlreadyUsed: InvalidCouponMessage.Text = "<p class=\"error\">The coupon code you entered is already in use.</p>"; break; case CouponResultType.InvalidForOrder: InvalidCouponMessage.Text = "<p class=\"error\">" + result.ErrorMessage + "</p>"; break; } InvalidCouponMessage.Visible = true; } CouponCode.Text = string.Empty; } }