public string UpdateOrDeleteCoupon(UniqueCoupon model, string actionType) { if (actionType.Equals("update", StringComparison.Ordinal)) { var updated = false; var coupon = _couponService.GetById(model.Id); if (coupon != null) { coupon.Code = model.Code; coupon.Expiration = model.Expiration; coupon.MaxRedemptions = model.MaxRedemptions; coupon.UsedRedemptions = model.UsedRedemptions; coupon.ValidFrom = model.ValidFrom; updated = _couponService.SaveCoupons(new List <UniqueCoupon> { coupon }); } return(updated ? "update_ok" : "update_nok"); } else { var deleted = _couponService.DeleteById(model.Id); return(deleted ? "delete_ok" : "delete_nok"); } }
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 }); }