Developer forum

Forum » Development » Am I doing this right?

Am I doing this right?


Reply

this is my code to see if the subscribing user already exists in the List:

 

Boolean bAddToNewsletterList = true;
Dynamicweb.NewsLetterV3.RecipientCollection currentUsers = new RecipientCollection();
foreach (Dynamicweb.NewsLetterV3.Recipient currentUser in currentUsers)

{
  if (currentUser.AccessUserEmail.Trim().ToLower() == MyOrder.CustomerEmail.Trim().ToLower())
  {
    bAddToNewsletterList = false; break;
  }
}
 

My question is ... where do I mention the List to search?

 

Dynamicweb.NewsLetterV3.RecipientCollection() does not accept any parameters.

 

 

Thank you.

 

 


Replies

 
Reply

You shold go the other way around and see if the caregory already exists in the recipients Subscriptions list.

 
Reply
Sorensen wrote:

You shold go the other way around and see if the caregory already exists in the recipients Subscriptions list.

 

So, what are you saying is to change that code to this:

 

 

 

Dynamicweb.NewsLetterV3.RandomPassword randPwd = new RandomPassword();

 

Dynamicweb.NewsLetterV3.Recipient MyRecipient = new Recipient();

MyRecipient.RecipientType = Consts.RecipientType.User;

MyRecipient.AccessUserActive = true;

MyRecipient.AccessUserName = MyOrder.CustomerName;

MyRecipient.AccessUserEmail = MyOrder.CustomerEmail;

MyRecipient.AccessUserPassword = randPwd.ToString(); //make a random password or something

MyRecipient.AccessUserMobile = MyOrder.CustomerCell;

 

Dynamicweb.NewsLetterV3.Subscription MySubscription = new

Subscription(NewsletterListID, Dynamicweb.Modules.Common.Constants.MailFormat.HTML);

 

if (!MyRecipient.Subscriptions.Contains(MySubscription))

{

      MyRecipient.Subscriptions.Add(MySubscription);

      MyRecipient.Save();

}

 

 

Where the .Contains check if the user already have a subscription and if not, then I add and save, is that it?

 

By the way, do you know why does the system execute this twice every time? per each order I have 2 inserts of the same User / Email.

 

I use this code to get into the Notification Subscriber, both nothing else, should I have an IF somewhere?

 

 

 

[Subscribe(Dynamicweb.Notifications.eCommerce.Order.Steps.CustomerInfoHarvested)]

public class NewsletterSubscription : NotificationSubscriber

{

   public override void OnNotify(string notification, object[] args)

   {

     //Code that gets myOrder and have the code above to add the subscription

   }

}

 

 
Reply

Yes, from the top of my head, that would be the way to do it.

 
Reply
Sorensen wrote:

Yes, from the top of my head, that would be the way to do it.

I just edited the message to ask one more question :)

 

You must be logged in to post in the forum