public ExtractCouponTransaction(String plateNumber, Stream responseStream) { this.PlateNumber = plateNumber; this.ProcessThread = new Thread(() => { try { var result = new CouponResult { ResultCode = ResultCode.Success }; var ticket = Engine.GetEngine().Storage.GetTicketByPlateNumber(plateNumber); if (ticket == null) { StreamUtils.WriteToStreamWithUF8(responseStream, IPSCMJsonConvert.ConvertToJson(new Result { ResultCode = ResultCode.SuccessButNoBinding })); } else { result.Info = new CouponInfo { TicketId = ticket.TicketId, Type = ticket.Type, Value = ticket.Value }; StreamUtils.WriteToStreamWithUF8(responseStream, IPSCMJsonConvert.ConvertToJson(result)); } responseStream.Flush(); responseStream.Close(); this.Status = TransactionStatus.Exhausted; } catch (Exception ex) { this.Status = TransactionStatus.Errored; Log.Error("Extract Coupon Transaction encountered a bad error!", ex); } finally { responseStream.Flush(); responseStream.Close(); } }); }
/// <summary> /// To get a specific Coupon from the data layer /// </summary> /// <param name="couponCode"></param> /// <returns></returns> public CouponResult GetCoupon(string couponCode) { var couponResult = new CouponResult { Success = true }; try { var coupon = CouponDataProvider.Get(couponCode); couponResult.Coupon = ConvertDataToBusinessModel(coupon); } catch (Exception exception) { couponResult.Success = false; couponResult.ErrorDescription = exception.Message; } return(couponResult); }
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; } }