示例#1
0
        public ActionResult ApplyDiscountOrGiftCardCode(VendrDiscountOrGiftCardCodeDto model)
        {
            try
            {
                using (var uow = _vendrApi.Uow.Create())
                {
                    var store = CurrentPage.GetStore();
                    var order = _vendrApi.GetCurrentOrder(store.Id)
                                .AsWritable(uow)
                                .Redeem(model.Code);

                    _vendrApi.SaveOrder(order);

                    uow.Complete();
                }
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError("code", "Failed to redeem discount code: " + ex.Message);

                return(IsAjaxRequest()
                    ? (ActionResult)Json(new { success = false, errors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage) })
                    : CurrentUmbracoPage());
            }

            return(IsAjaxRequest()
                ? (ActionResult)Json(new { success = true })
                : RedirectToCurrentUmbracoPage());
        }
示例#2
0
        public ActionResult ApplyDiscountOrGiftCardCode(VendrDiscountOrGiftCardCodeDto model)
        {
            try
            {
                using (var uow = _vendrApi.Uow.Create())
                {
                    var store = CurrentPage.GetStore();
                    var order = _vendrApi.GetCurrentOrder(store.Id)
                                .AsWritable(uow)
                                .Redeem(model.Code);

                    _vendrApi.SaveOrder(order);

                    uow.Complete();
                }
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError("", "Failed to redeem discount code: " + ex.Message);

                return(CurrentUmbracoPage());
            }

            return(RedirectToCurrentUmbracoPage());
        }