/// <summary> /// The visit. /// </summary> /// <param name="lineItem"> /// The line item. /// </param> public void Visit(ILineItem lineItem) { if (lineItem.LineItemType != LineItemType.Discount) { return; } if (!lineItem.ExtendedData.ContainsKey(Core.Constants.ExtendedDataKeys.CouponReward)) { return; } var json = lineItem.ExtendedData.GetValue(Core.Constants.ExtendedDataKeys.CouponReward); var offerSettings = JsonConvert.DeserializeObject <OfferSettingsDisplay>(json); var offerRedeemed = new OfferRedeemed( offerSettings.OfferCode, offerSettings.OfferProviderKey, lineItem.ContainerKey, offerSettings.Key); offerRedeemed.CustomerKey = _customerKey; offerRedeemed.ExtendedData.SetValue(Core.Constants.ExtendedDataKeys.CouponReward, json); _redemptions.Add(offerRedeemed); }
/// <summary> /// Creates an <see cref="IOfferRedeemed"/> record /// </summary> /// <param name="offerSettings"> /// The offer settings. /// </param> /// <param name="invoice"> /// The invoice. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> /// <returns> /// The <see cref="IOfferRedeemed"/>. /// </returns> public IOfferRedeemed CreateOfferRedeemedWithKey(IOfferSettings offerSettings, IInvoice invoice, bool raiseEvents = true) { var redemption = new OfferRedeemed( offerSettings.OfferCode, offerSettings.OfferProviderKey, invoice.Key, offerSettings.Key); if (raiseEvents) { if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IOfferRedeemed>(redemption), this)) { redemption.WasCancelled = true; return(redemption); } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateOfferRedeemedRepository(uow)) { repository.AddOrUpdate(redemption); uow.Commit(); } } if (raiseEvents) { Created.RaiseEvent(new Events.NewEventArgs <IOfferRedeemed>(redemption), this); } return(redemption); }
/// <summary> /// Builds a <see cref="IOfferRedeemed"/> give a <see cref="OfferRedeemedDto"/>. /// </summary> /// <param name="dto"> /// The dto. /// </param> /// <returns> /// The <see cref="IOfferRedeemed"/>. /// </returns> public IOfferRedeemed BuildEntity(OfferRedeemedDto dto) { var entity = new OfferRedeemed(dto.OfferCode, dto.OfferProviderKey, dto.InvoiceKey, dto.OfferSettingsKey) { Key = dto.Key, RedeemedDate = dto.RedeemedDate, CustomerKey = dto.CustomerKey, ExtendedData = new ExtendedDataCollection(dto.ExtendedData), CreateDate = dto.CreateDate, UpdateDate = dto.UpdateDate }; entity.ResetDirtyProperties(); return(entity); }