/// <summary>
        /// Makes a call to the StormPost API to retrieve the Recipient record, by uniqueId
        /// </summary>
        /// <param name="uniqueId">StormPost Unique ID</param>
        /// <returns></returns>
        private NewsletterSubscriber retrieveSubscriber(int uniqueId)
        {
            NewsletterSubscriber        output;
            Dictionary <string, string> demographics;

            MemberServices.stormpost.api.Recipient    recipient;
            stormpost.api.SoapRequestProcessorService api;
            stormpost.api.ListSubscription[]          subscriptions;

            output = new NewsletterSubscriber();
            output.Subscriptions = new List <Newsletter>();

            // Retrieve the StormPost Subscriber info
            api = new MemberServices.stormpost.api.SoapRequestProcessorService();
            api.authenticationValue          = new MemberServices.stormpost.api.authentication();
            api.authenticationValue.username = ConfigurationManager.AppSettings["newsletter-api-username"];
            api.authenticationValue.password = ConfigurationManager.AppSettings["newsletter-api-password"];
            recipient = api.getRecipient(uniqueId);


            // Retrieve the Subscription data
            output.UniqueID     = recipient.recipID.Value;
            output.EmailAddress = recipient.address;
            subscriptions       = api.getRecipientSubscriptions(recipient.recipID.Value);
            subscriptions       = subscriptions.Where(s => s.subscribed)
                                  .ToArray();

            // Populate the subscriptions collection on the output object
            foreach (stormpost.api.ListSubscription sub in subscriptions)
            {
                output.Subscriptions.Add(new Newsletter()
                {
                    ListId = sub.listID.Value,
                    Name   = sub.listTitle
                });
            }

            // Retrive Demographics; StormPost refers to custom demographic fields by _Custom01, _Custom02, etc.
            demographics         = recipient.GetDemographics();
            output.First_Name    = demographics.Keys.Contains("FirstName") ? demographics["FirstName"] : "";
            output.Last_Name     = demographics.Keys.Contains("LastName") ? demographics["LastName"] : "";
            output.Member_Type   = demographics.Keys.Contains("_Custom01") ? demographics["_Custom01"] : "";
            output.Member_Source = demographics.Keys.Contains("_Custom02") ? demographics["_Custom02"] : "";

            // Parse Expire date from the value in _Custom03
            string   temp    = demographics.Keys.Contains("_Custom03") ? demographics["_Custom03"] : "";
            DateTime tmpDate = new DateTime();

            output.Member_Expire_Date = DateTime.TryParse(temp, out tmpDate) ? (DateTime?)tmpDate : (DateTime?)null;


            return(output);
        }
        public bool UpdateSubscriber(NewsletterSubscriber subscriber)
        {
            stormpost.api.SoapRequestProcessorService api;
            stormpost.api.Recipient recipient;

            try
            {
                api = new MemberServices.stormpost.api.SoapRequestProcessorService();
                api.authenticationValue          = new MemberServices.stormpost.api.authentication();
                api.authenticationValue.username = ConfigurationManager.AppSettings["newsletter-api-username"];
                api.authenticationValue.password = ConfigurationManager.AppSettings["newsletter-api-password"];

                recipient         = api.getRecipient(subscriber.UniqueID);
                recipient.address = subscriber.EmailAddress;
                recipient.SetDemographic("FirstName", subscriber.First_Name);
                recipient.SetDemographic("LastName", subscriber.Last_Name);
                recipient.SetDemographic("_Custom01", subscriber.Member_Type);
                recipient.SetDemographic("_Custom02", subscriber.Member_Source);
                recipient.SetDemographic("_Custom03", subscriber.Member_Expire_Date.GetValueOrDefault(new DateTime(1900, 1, 1)).ToString("yyyy-MM-dd"));

                api.updateRecipient(recipient);
                return(true);
            }
            catch (Exception ex)
            {
                string argString = String.Format("Unique Id: {0}\r\n\r\n", subscriber.UniqueID.ToString());
                new SupportClasses.Mailer().SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                                                      ConfigurationManager.AppSettings["mailservicepwd"],
                                                      "NewsletterService ERROR - " + ex.GetType().Name,
                                                      "*****@*****.**",
                                                      ConfigurationManager.AppSettings["newsletter-erroremailto"],
                                                      "", "", argString + ex.ToString(), false,
                                                      ConfigurationManager.AppSettings["erroremailsmtpserver"]);
                throw;
            }
        }
        /// <summary>
        /// Makes a call to the StormPost API to retrieve the Recipient record, by uniqueId
        /// </summary>
        /// <param name="uniqueId">StormPost Unique ID</param>
        /// <returns></returns>
        private NewsletterSubscriber retrieveSubscriber(int uniqueId)
        {
            NewsletterSubscriber output;
            Dictionary<string, string> demographics;
            MemberServices.stormpost.api.Recipient recipient;
            stormpost.api.SoapRequestProcessorService api;
            stormpost.api.ListSubscription[] subscriptions;

            output = new NewsletterSubscriber();
            output.Subscriptions = new List<Newsletter>();

            // Retrieve the StormPost Subscriber info
            api = new MemberServices.stormpost.api.SoapRequestProcessorService();
            api.authenticationValue = new MemberServices.stormpost.api.authentication();
            api.authenticationValue.username = ConfigurationManager.AppSettings["newsletter-api-username"];
            api.authenticationValue.password = ConfigurationManager.AppSettings["newsletter-api-password"];
            recipient = api.getRecipient(uniqueId);


            // Retrieve the Subscription data
            output.UniqueID = recipient.recipID.Value;
            output.EmailAddress = recipient.address;
            subscriptions = api.getRecipientSubscriptions(recipient.recipID.Value);
            subscriptions = subscriptions.Where(s => s.subscribed)
                                         .ToArray();

            // Populate the subscriptions collection on the output object
            foreach (stormpost.api.ListSubscription sub in subscriptions)
            {
                output.Subscriptions.Add(new Newsletter()
                {
                    ListId = sub.listID.Value,
                    Name = sub.listTitle
                });
            }

            // Retrive Demographics; StormPost refers to custom demographic fields by _Custom01, _Custom02, etc.
            demographics = recipient.GetDemographics();
            output.First_Name = demographics.Keys.Contains("FirstName") ? demographics["FirstName"] : "";
            output.Last_Name = demographics.Keys.Contains("LastName") ? demographics["LastName"] : "";
            output.Member_Type = demographics.Keys.Contains("_Custom01") ? demographics["_Custom01"] : "";
            output.Member_Source = demographics.Keys.Contains("_Custom02") ? demographics["_Custom02"] : "";

            // Parse Expire date from the value in _Custom03
            string temp = demographics.Keys.Contains("_Custom03") ? demographics["_Custom03"] : "";
            DateTime tmpDate = new DateTime();
            output.Member_Expire_Date = DateTime.TryParse(temp, out tmpDate) ? (DateTime?)tmpDate : (DateTime?)null;


            return output;


        }
        public bool UpdateSubscriber(NewsletterSubscriber subscriber)
        {
            stormpost.api.SoapRequestProcessorService api;
            stormpost.api.Recipient recipient;

            try
            {
                api = new MemberServices.stormpost.api.SoapRequestProcessorService();
                api.authenticationValue = new MemberServices.stormpost.api.authentication();
                api.authenticationValue.username = ConfigurationManager.AppSettings["newsletter-api-username"];
                api.authenticationValue.password = ConfigurationManager.AppSettings["newsletter-api-password"];

                recipient = api.getRecipient(subscriber.UniqueID);
                recipient.address = subscriber.EmailAddress;
                recipient.SetDemographic("FirstName", subscriber.First_Name);
                recipient.SetDemographic("LastName", subscriber.Last_Name);
                recipient.SetDemographic("_Custom01", subscriber.Member_Type);
                recipient.SetDemographic("_Custom02", subscriber.Member_Source);
                recipient.SetDemographic("_Custom03", subscriber.Member_Expire_Date.GetValueOrDefault(new DateTime(1900, 1,1)).ToString("yyyy-MM-dd"));
                
                api.updateRecipient(recipient);
                return true;
            }
            catch (Exception ex)
            {
                string argString = String.Format("Unique Id: {0}\r\n\r\n", subscriber.UniqueID.ToString());
                new SupportClasses.Mailer().SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                    ConfigurationManager.AppSettings["mailservicepwd"],
                    "NewsletterService ERROR - " + ex.GetType().Name,
                    "*****@*****.**",
                    ConfigurationManager.AppSettings["newsletter-erroremailto"],
                    "", "", argString + ex.ToString(), false,
                    ConfigurationManager.AppSettings["erroremailsmtpserver"]);
                throw;
            }

        }