public PromotionFilterContext Filter(PromotionFilterContext filterContext, IEnumerable <string> couponCodes) { var codes = couponCodes.ToList(); var userEmail = PrincipalInfo.CurrentPrincipal?.GetCustomerContact()?.Email; foreach (var includedPromotion in filterContext.IncludedPromotions) { var couponCode = includedPromotion.Coupon.Code; var uniqueCodes = _couponService.GetByPromotionId(includedPromotion.ContentLink.ID); if (string.IsNullOrEmpty(couponCode) && !(uniqueCodes?.Any() ?? false)) { continue; } if (!string.IsNullOrEmpty(couponCode)) { CheckSingleCoupon(filterContext, codes, couponCode, includedPromotion); } else { CheckMultipleCoupons(filterContext, codes, includedPromotion, uniqueCodes); } } return(filterContext); }
public ActionResult EditPromotionCoupons(int id) { var promotion = _contentLoader.Get <PromotionData>(new ContentReference(id)); var coupons = _couponService.GetByPromotionId(id); return(View(new PromotionCouponsViewModel { Coupons = coupons ?? new List <UniqueCoupon>(), Promotion = promotion, PromotionId = promotion.ContentLink.ID, MaxRedemptions = 1 })); }
private void CheckMultiple(PromotionData promotion, PromotionInformation promotionInformation) { var uniqueCodes = _uniqueCouponService.GetByPromotionId(promotion.ContentLink.ID); if (uniqueCodes == null || !uniqueCodes.Any()) { return; } var uniqueCode = uniqueCodes.FirstOrDefault(x => x.Code.Equals(promotionInformation.CouponCode, StringComparison.OrdinalIgnoreCase)); if (uniqueCode == null) { return; } uniqueCode.UsedRedemptions++; _uniqueCouponService.SaveCoupons(new List <UniqueCoupon> { uniqueCode }); }