public string GetListMember(string apiKey, string listId, string subscriberEmail = "")
System.Threading.Tasks.Task<string> task = System.Threading.Tasks.Task.Run<string>(async () => await GetListMemberWorker(apiKey, listId, subscriberEmail));
catch(AggregateException e)
System.Diagnostics.Debug.WriteLine(e.InnerException.GetType().ToString());
result = e.InnerException.Message;
public bool LookupMailchimpListIsSubscribedToLifestyle(string a_EmailAddress)
if(string.IsNullOrEmpty(a_EmailAddress)) { return false; }
if(System.Web.HttpContext.Current.Session["HasMailingListCheckBeenPerformed"] != null && Convert.ToBoolean(System.Web.HttpContext.Current.Session["HasMailingListCheckBeenPerformed"]))
return System.Web.HttpContext.Current.Session["IsCurrentlySubscribedToMailinglist"] != null ? Convert.ToBoolean(System.Web.HttpContext.Current.Session["IsCurrentlySubscribedToMailinglist"]) : false;
bool MailchimpIsSubscribed = false;
string strStoreNum = "VPOLifestyle";
string strAPIKeyConfigName = string.Format("Mailchimp.APIKey.{0}", strStoreNum);
string strListConfigName = string.Format("Mailchimp.ListID.{0}", strStoreNum);
string strAPIKey = AppLogic.AppConfig(strAPIKeyConfigName);
string strListID = AppLogic.AppConfig(strListConfigName);
MailChimp.Net.Interfaces.IMailChimpManager mailChimpManager = new MailChimp.Net.MailChimpManager(strAPIKey);
var MailchimpAPIResult = GetListMember(strAPIKey, strListID, a_EmailAddress);
if((MailchimpAPIResult.Length > 29 && MailchimpAPIResult.Substring(0, 30) == "Unable to find the resource at") || MailchimpAPIResult == Convert.ToString(System.Net.HttpStatusCode.NotFound) || MailchimpAPIResult == MailChimp.Net.Models.Status.Pending.ToString())
MailchimpIsSubscribed = false;
else if(MailchimpAPIResult == MailChimp.Net.Models.Status.Subscribed.ToString().ToLower())
MailchimpIsSubscribed = true;
System.Web.HttpContext.Current.Session["IsCurrentlySubscribedToMailinglist"] = MailchimpIsSubscribed;
System.Web.HttpContext.Current.Session["HasMailingListCheckBeenPerformed"] = true;
return MailchimpIsSubscribed;
private static async System.Threading.Tasks.Task<string> GetListMemberWorker(string apiKey, string listId, string subscriberEmail = "")
IMailChimpManager manager = new MailChimpManager(apiKey);
MailChimp.Net.Models.Member foundMember;
foundMember = await manager.Members.GetAsync(listId, subscriberEmail);
return foundMember.Status.ToString().ToLower();