Exemplo n.º 1
0
        public ActionResult RemoveDiscountOrGiftCardCode(VendrDiscountOrGiftCardCodeDto model)
        {
            try
            {
                using (var uow = _vendrApi.Uow.Create())
                {
                    var store = CurrentPage.GetStore();
                    var order = _vendrApi.GetCurrentOrder(store.Id)
                                .AsWritable(uow)
                                .Unredeem(model.Code);

                    _vendrApi.SaveOrder(order);

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

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

            return(IsAjaxRequest()
                ? (ActionResult)Json(new { success = true }, JsonRequestBehavior.AllowGet)
                : RedirectToCurrentUmbracoPage());
        }
Exemplo n.º 2
0
        public ActionResult RemoveDiscountOrGiftCardCode(VendrDiscountOrGiftCardCodeDto model)
        {
            try
            {
                using (var uow = _vendrApi.Uow.Create())
                {
                    var store = CurrentPage.GetStore();
                    var order = _vendrApi.GetCurrentOrder(store.Id)
                                .AsWritable(uow)
                                .Unredeem(model.Code);

                    _vendrApi.SaveOrder(order);

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

                return(CurrentUmbracoPage());
            }

            return(RedirectToCurrentUmbracoPage());
        }