/// <summary> /// Inserts a newsletter subscription /// </summary> /// <param name="newsLetterSubscription">NewsLetter subscription</param> /// <param name="publishSubscriptionEvents">if set to <c>true</c> [publish subscription events].</param> public virtual async Task InsertNewsLetterSubscription(NewsLetterSubscription newsLetterSubscription, bool publishSubscriptionEvents = true) { if (newsLetterSubscription == null) { throw new ArgumentNullException("newsLetterSubscription"); } //Handle e-mail newsLetterSubscription.Email = CommonHelper.EnsureSubscriberEmailOrThrow(newsLetterSubscription.Email); //Persist await _subscriptionRepository.InsertAsync(newsLetterSubscription); //Publish the subscription event if (newsLetterSubscription.Active) { await PublishSubscriptionEvent(newsLetterSubscription.Email, true, publishSubscriptionEvents); } //save history await newsLetterSubscription.SaveHistory <NewsLetterSubscription>(_historyService); //Publish event await _mediator.EntityInserted(newsLetterSubscription); }
/// <summary> /// Updates a newsletter subscription /// </summary> /// <param name="newsLetterSubscription">NewsLetter subscription</param> /// <param name="publishSubscriptionEvents">if set to <c>true</c> [publish subscription events].</param> public virtual async Task UpdateNewsLetterSubscription(NewsLetterSubscription newsLetterSubscription, bool publishSubscriptionEvents = true) { if (newsLetterSubscription == null) { throw new ArgumentNullException("newsLetterSubscription"); } //get previous newsLetterSubscription record var prevnewsLetterSubscription = await _subscriptionRepository.GetByIdAsync(newsLetterSubscription.Id); //Handle e-mail newsLetterSubscription.Email = CommonHelper.EnsureSubscriberEmailOrThrow(newsLetterSubscription.Email); //Persist await _subscriptionRepository.UpdateAsync(newsLetterSubscription); //save history await newsLetterSubscription.SaveHistory <NewsLetterSubscription>(_historyService); //Publish the un/subscribe event if (prevnewsLetterSubscription != null) { if (newsLetterSubscription.Active && !prevnewsLetterSubscription.Active) { await PublishSubscriptionEvent(newsLetterSubscription.Email, true, publishSubscriptionEvents); } if (!newsLetterSubscription.Active && prevnewsLetterSubscription.Active) { await PublishSubscriptionEvent(newsLetterSubscription.Email, false, publishSubscriptionEvents); } } //Publish event await _mediator.EntityUpdated(newsLetterSubscription); }
/// <summary> /// Inserts a newsletter subscription /// </summary> /// <param name="newsLetterSubscription">NewsLetter subscription</param> /// <param name="publishSubscriptionEvents">if set to <c>true</c> [publish subscription events].</param> public virtual void InsertNewsLetterSubscription(NewsLetterSubscription newsLetterSubscription, bool publishSubscriptionEvents = true) { if (newsLetterSubscription == null) { throw new ArgumentNullException("newsLetterSubscription"); } //Handle e-mail newsLetterSubscription.Email = CommonHelper.EnsureSubscriberEmailOrThrow(newsLetterSubscription.Email); //Persist _subscriptionRepository.Insert(newsLetterSubscription); //Publish the subscription event if (newsLetterSubscription.Active) { PublishSubscriptionEvent(newsLetterSubscription.Email, true, publishSubscriptionEvents); } //save history newsLetterSubscription.SaveHistory <NewsLetterSubscription>(); //Publish event _eventPublisher.EntityInserted(newsLetterSubscription); }
/// <summary> /// Updates a newsletter subscription /// </summary> /// <param name="newsLetterSubscription">NewsLetter subscription</param> /// <param name="publishSubscriptionEvents">if set to <c>true</c> [publish subscription events].</param> public virtual async Task UpdateNewsLetterSubscription(NewsLetterSubscription newsLetterSubscription, bool publishSubscriptionEvents = true) { if (newsLetterSubscription == null) { throw new ArgumentNullException("newsLetterSubscription"); } //Handle e-mail newsLetterSubscription.Email = CommonHelper.EnsureSubscriberEmailOrThrow(newsLetterSubscription.Email); //Persist await _subscriptionRepository.UpdateAsync(newsLetterSubscription); //save history await newsLetterSubscription.SaveHistory <NewsLetterSubscription>(_historyService); //Publish event await _eventPublisher.EntityUpdated(newsLetterSubscription); }