Exemple #1
0
        /// <summary>
        /// Mails the chimp_ subscribe.
        /// Will go through each ContactId in the ContactIdslist, retrieve the Contacts.FirstName, Contacts.LastName, Contacts.Email.
        /// Invoke the MailChimp API listBatchSubscribe
        /// </summary>
        /// <param name="ContactIds">The contact ids.</param>
        /// <param name="MailChimpListId">The mail chimp list id.</param>
        /// <returns></returns>
        public MailChimp_Response MailChimp_Subscribe(List <int> ContactIds, string MailChimpListId)
        {
            MailChimp_Response response = new MailChimp_Response();

            response.hdr = new RespHdr();

            if (ContactIds == null || ContactIds.Count == 0)
            {
                response.hdr.Successful = false;
                response.hdr.StatusInfo = string.Format("MailChimpMgr: ContactIds is null.");
                return(response);
            }

            if (string.IsNullOrEmpty(MailChimpListId))
            {
                response.hdr.Successful = false;
                response.hdr.StatusInfo = string.Format("MailChimpMgr: MailChimpListId is null.");
                return(response);
            }

            string apiKey = string.Empty;

            apiKey = GetApiKey(MailChimpListId);
            if (string.IsNullOrEmpty(apiKey))
            {
                response.hdr.Successful = false;
                response.hdr.StatusInfo = string.Format("MailChimpMgr: MailChimpAPIKey is null.");
                return(response);
            }

            var contacts = _dataAccess.GetMailChimpContact(ContactIds);

            return(_mailChimpApi.ListBatchSubscribe(apikey: apiKey, mailChimpListId: MailChimpListId, subscriberList: contacts));
        }
Exemple #2
0
        /// <summary>
        /// Mails the chimp_ unsubscribe.
        /// Will retrieve the Contacts.FirstName, Contacts.LastName, Contacts.Email using the ContactId.
        /// Invoke the MailChimp API listUnsubscribe
        /// </summary>
        /// <param name="ContactId">The contact id.</param>
        /// <param name="MailChimpListId">The mail chimp list id.</param>
        /// <returns></returns>
        public MailChimp_Response MailChimp_Unsubscribe(int ContactId, string MailChimpListId)
        {
            MailChimp_Response response = new MailChimp_Response();

            response.hdr = new RespHdr();

            if (ContactId <= 0)
            {
                response.hdr.Successful = false;
                response.hdr.StatusInfo = string.Format("MailChimpMgr: ContactId is less than 0.");
                return(response);
            }

            if (string.IsNullOrEmpty(MailChimpListId))
            {
                response.hdr.Successful = false;
                response.hdr.StatusInfo = string.Format("MailChimpMgr: MailChimpListId is null.");
                return(response);
            }

            string apiKey = string.Empty;

            apiKey = GetApiKey(MailChimpListId);
            if (string.IsNullOrEmpty(apiKey))
            {
                response.hdr.Successful = false;
                response.hdr.StatusInfo = string.Format("MailChimpMgr: MailChimpAPIKey is null.");
                return(response);
            }

            var contact = _dataAccess.GetMailChimpContact(ContactId);

            return(_mailChimpApi.ListUnsubscribe(apikey: apiKey, mailChimpListId: MailChimpListId, subscriber: contact));
        }
        /// <summary>
        /// Mails the chimp_ unsubscribe.
        ///  Will go through each ContactId in the ContactIdslist, retrieve the Contacts.FirstName, Contacts.LastName, Contacts.Email.
        /// Invoke the MailChimp API listBatchUnsubscribe
        /// </summary>
        /// <param name="ContactIds">The contact ids.</param>
        /// <param name="MailChimpListId">The mail chimp list id.</param>
        /// <returns></returns>
        public MailChimp_Response MailChimp_Unsubscribe(List <int> ContactIds, string MailChimpListId)
        {
            MailChimp_Response response = new MailChimp_Response();

            response.hdr = new RespHdr();

            response.hdr.Successful = true;
            response.hdr.StatusInfo = "";
            return(response);
        }
Exemple #4
0
        /// <summary>
        /// Lists the batch subscribe.
        /// </summary>
        /// <param name="apikey">The apikey.</param>
        /// <param name="mailChimpListId">The mail chimp list id.</param>
        /// <param name="subscriberList">The subscriber list.</param>
        /// <returns></returns>
        public MailChimp_Response ListBatchSubscribe(string apikey, string mailChimpListId, List <Table.MailChimpContact> subscriberList)
        {
            //todo:pass
            MailChimp_Response response = new MailChimp_Response();

            response.hdr = new RespHdr();
            string StatusInfo = "";

            var input = GetListBatchSubscribeInput(apikey, mailChimpListId);
            // method parameters
            var batch = new List <Dictionary <string, object> >();

            foreach (Table.MailChimpContact sub_rec in subscriberList)
            {
                Dictionary <string, object> entry = new Dictionary <string, object>();
                entry.Add("EMAIL", sub_rec.Email);
                entry.Add("EMAIL_TYPE", EnumValues.emailType.NotSpecified);
                entry.Add("FNAME", sub_rec.FirstName);
                entry.Add("LNAME", sub_rec.LastName);
                batch.Add(entry);
            }
            input.parms.batch = batch;

            // execution
            var cmd    = new listBatchSubscribe(input);
            var output = cmd.Execute();

            // output, format with user control
            if (output.api_ErrorMessages.Count > 0)
            {
                StringBuilder sbErrDetail = new StringBuilder();
                foreach (var apiErrorMessage in output.api_ErrorMessages)
                {
                    sbErrDetail.AppendLine(string.Format("error code:{0},error msg:{1}", apiErrorMessage.code,
                                                         apiErrorMessage.error));
                    StatusInfo = apiErrorMessage.error;
                }
                string errMsg = string.Format("apikey:{4}mailChimpListId:{5}\r\n{0}{1}{2}{3}", output.api_Request, output.api_Response,     // raw data
                                              sbErrDetail, output.api_ValidatorMessages, apikey, mailChimpListId);
                int Event_id = 5016;
                EventLog.WriteEntry(InfoHubEventLog.LogSource, errMsg, EventLogEntryType.Warning, Event_id, Category);
                response.hdr.Successful = false;
                response.hdr.StatusInfo = "MailChimpMgr: " + StatusInfo;
                return(response);
            }
            else
            {
                //Console.Write(output);
                response.hdr.Successful = true;
                response.hdr.StatusInfo = "";
                return(response);
            }
        }
        /// <summary>
        /// Mails the chimp_ sync now.
        /// Retrieve the Branches.MailChimpAPIKey and invoke the MailChimp API lists to get all the MailChimp lists for the branch and perform the steps below:
        ///     Update the MailChimpLists table with the records obtained from MailChimp.
        ///     Compare the list of MailChimp lists against the records from the MailChimpLists table. If the database record within the MailChimpLists table is not found in the list from MailChimp, delete it from the MailChimpLists table and the associated ContactMailCampaigns record referencing the same LID.
        /// Retrieve the Branches.MailChimpAPIKey and invoke the MailChimp API campaigns to get all the MailChimpcampaigns for the branch and perform the steps below:
        ///     Update the MailChimpCampaigns table with the records obtained from MailChimp.
        ///     Compare the list of MailChimp campaigns against the records from the MailChimpCampaignstable. If the database record within the MailChimpCampaignstable is not found in the list from MailChimp, delete it from the MailChimpCampaignstable and update the associatedContactMailCampaigns records withContactMailCampaigns.CID=NULL referencing the same CID.
        /// </summary>
        /// <param name="BranchId">The branch id.</param>
        /// <returns></returns>
        public MailChimp_Response MailChimp_SyncNow(int BranchId)
        {
            MailChimp_Response response = new MailChimp_Response();

            response.hdr = new RespHdr();

            if (BranchId <= 0)
            {
                response.hdr.Successful = false;
                response.hdr.StatusInfo = string.Format("MailChimpMgr: BranchId is null.");
                return(response);
            }

            return(_mailChimpManager.MailChimp_SyncNow(BranchId));
        }
Exemple #6
0
        /// <summary>
        /// Lists the subscribe.
        /// </summary>
        /// <param name="apikey">The apikey.</param>
        /// <param name="mailChimpListId">The mail chimp list id.</param>
        /// <param name="subscriber">The subscriber.</param>
        /// <returns></returns>
        public MailChimp_Response ListSubscribe(string apikey, string mailChimpListId, Table.MailChimpContact subscriber)
        {
            //todo:pass
            MailChimp_Response response = new MailChimp_Response();

            response.hdr = new RespHdr();
            string StatusInfo = "";

            var input = GetListSubscribeInput(apikey, mailChimpListId);

            var entry = new Dictionary <string, object>();

            entry.Add("EMAIL", subscriber.Email);
            entry.Add("FNAME", subscriber.FirstName);
            entry.Add("LNAME", subscriber.LastName);
            input.parms.merge_vars    = entry;
            input.parms.email_type    = EnumValues.emailType.NotSpecified;
            input.parms.email_address = subscriber.Email;

            var cmd    = new listSubscribe(input);
            var output = cmd.Execute();

            if (output.api_ErrorMessages.Count > 0)
            {
                StringBuilder sbErrDetail = new StringBuilder();
                foreach (var apiErrorMessage in output.api_ErrorMessages)
                {
                    sbErrDetail.AppendLine(string.Format("error code:{0},error msg:{1}", apiErrorMessage.code,
                                                         apiErrorMessage.error));
                    StatusInfo = apiErrorMessage.error;
                }
                string errMsg = string.Format("apikey:{4}mailChimpListId:{5}\r\n{0}{1}{2}{3}", output.api_Request, output.api_Response,     // raw data
                                              sbErrDetail, output.api_ValidatorMessages, apikey, mailChimpListId);
                int Event_id = 5018;
                EventLog.WriteEntry(InfoHubEventLog.LogSource, errMsg, EventLogEntryType.Warning, Event_id, Category);
                response.hdr.Successful = false;
                response.hdr.StatusInfo = "MailChimpMgr: " + StatusInfo;
                return(response);
            }
            else
            {
                //Console.Write(output);
                response.hdr.Successful = true;
                response.hdr.StatusInfo = "";
                return(response);
            }
        }
Exemple #7
0
        /// <summary>
        /// Lists the batch unsubscribe.
        /// </summary>
        /// <param name="apikey">The apikey.</param>
        /// <param name="mailChimpListId">The mail chimp list id.</param>
        /// <param name="subscriberList">The subscriber list.</param>
        /// <returns></returns>
        public MailChimp_Response ListBatchUnsubscribe(string apikey, string mailChimpListId, List <Table.MailChimpContact> subscriberList)
        {
            //todo:pass
            MailChimp_Response response = new MailChimp_Response();

            response.hdr = new RespHdr();
            string StatusInfo = "";

            var input        = GetListBatchUnsubscribeInput(apikey, mailChimpListId);
            var deleteEmails = (from subscriber in subscriberList select subscriber.Email).ToList();

            input.parms.emails = deleteEmails;

            // execution
            var cmd    = new listBatchUnsubscribe(input);
            var output = cmd.Execute();

            if (output.api_ErrorMessages.Count > 0)
            {
                StringBuilder sbErrDetail = new StringBuilder();
                foreach (var apiErrorMessage in output.api_ErrorMessages)
                {
                    sbErrDetail.AppendLine(string.Format("error code:{0},error msg:{1}", apiErrorMessage.code,
                                                         apiErrorMessage.error));
                    StatusInfo = apiErrorMessage.error;
                }
                string errMsg = string.Format("apikey:{4}mailChimpListId:{5}\r\n{0}{1}{2}{3}", output.api_Request, output.api_Response,     // raw data
                                              sbErrDetail, output.api_ValidatorMessages, apikey, mailChimpListId);
                int Event_id = 5017;
                EventLog.WriteEntry(InfoHubEventLog.LogSource, errMsg, EventLogEntryType.Warning, Event_id, Category);
                response.hdr.Successful = false;
                response.hdr.StatusInfo = "MailChimpMgr: " + StatusInfo;
                return(response);
            }
            else
            {
                //Console.Write(output);
                response.hdr.Successful = true;
                response.hdr.StatusInfo = "";
                return(response);
            }
        }
Exemple #8
0
        /// <summary>
        /// Mails the chimp_ sync now.
        /// </summary>
        /// <param name="BranchId">The branch id.</param>
        /// <returns></returns>
        public MailChimp_Response MailChimp_SyncNow(int BranchId)
        {
            MailChimp_Response response = new MailChimp_Response();

            response.hdr = new RespHdr();

            string mailChimpAPIKey = GetMailChimpAPIKey(BranchId);

            if (string.IsNullOrEmpty(mailChimpAPIKey))
            {
                string err      = string.Format("MailChimpAPIKey is empty for branchId:{0}", BranchId);
                int    Event_id = 2010;
                EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
                response.hdr.Successful = false;
                response.hdr.StatusInfo = string.Format("MailChimpMgr: MailChimpAPIKey is empty for branchId:{0}", BranchId);
                return(response);
            }

            try
            {
                MailChimpListSync(BranchId, mailChimpAPIKey);
                MailChimpCampaignSync(BranchId, mailChimpAPIKey);
            }
            catch (Exception exception)
            {
                string err = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + exception.Message + "\r\n\r\nStackTrace: " + exception.StackTrace;
                Trace.TraceError(exception.Message);
                int Event_id = 2011;
                EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category);
                response.hdr.Successful = false;
                response.hdr.StatusInfo = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + exception.Message;
                return(response);
            }

            response.hdr.Successful = true;
            response.hdr.StatusInfo = "";
            return(response);
        }