Exemplo n.º 1
0
        public ActionResult AddPromoCode(Int32 basketPartId, String promoCode)
        {
            String message          = null;
            String currentPromoCode = null;

            if (!String.IsNullOrEmpty(promoCode))
            {
                PromoCodeEntryResult result = null;

                Exception exception = this._webStoreServices.UsingClient(
                    c =>
                {
                    result = c.BasketClient.ApplyPromoCodes(this._webStoreServices.CurrentUserName, this._webStoreServices.BasketName, new[] { promoCode }).FirstOrDefault(r => String.Equals(r.PromoCode, promoCode, StringComparison.OrdinalIgnoreCase));

                    if (result == null || result.State != PromoCodeEntryState.Added)
                    {
                        currentPromoCode = promoCode;
                        message          = this._localizer("Promo code is not applicable").ToString();
                    }
                }
                    );

                if (exception != null)
                {
                    currentPromoCode = promoCode;
                    message          = this._localizer("An unexpected error has occured").ToString();
                }
                else if (result != null)
                {
                    this._basketEventHandlers.Trigger(h => h.PromoCodeAdded(result));
                }
            }

            return(this.GetBasket(basketPartId, currentPromoCode, message));
        }
Exemplo n.º 2
0
        public ActionResult RemovePromoCode(Int32 basketPartId, String promoCode)
        {
            String message = null;

            if (!String.IsNullOrEmpty(promoCode))
            {
                PromoCodeEntryResult result = null;

                if (this._webStoreServices.UsingClient(c => result = c.BasketClient.RemovePromoCodes(this._webStoreServices.CurrentUserName, this._webStoreServices.BasketName, promoCode).FirstOrDefault(r => String.Equals(r.PromoCode, promoCode, StringComparison.OrdinalIgnoreCase))) != null)
                {
                    message = this._localizer("An unexpected error has occured").ToString();
                }
                else if (result != null)
                {
                    this._basketEventHandlers.Trigger(h => h.PromoCodeRemoved(result));
                }
            }

            return(this.GetBasket(basketPartId, null, message));
        }