Beispiel #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));
        }
Beispiel #2
0
        public void ListBatchSubscribe()
        {
            var subscribers = new List <Table.MailChimpContact>
            {
                new Table.MailChimpContact
                {
                    Email     = "*****@*****.**",
                    FirstName = "Jac11",
                    LastName  = "Zhang11",
                }, new Table.MailChimpContact
                {
                    Email     = "*****@*****.**",
                    FirstName = "Jac12",
                    LastName  = "Zhang12",
                }, new Table.MailChimpContact
                {
                    Email     = "*****@*****.**",
                    FirstName = "Jac13",
                    LastName  = "Zhang13"
                }, new Table.MailChimpContact
                {
                    Email     = "*****@*****.**",
                    FirstName = "Jac14",
                    LastName  = "Zhang14"
                }
            };


            Assert.AreEqual(true, mailChimpApi.ListBatchSubscribe(_apiKey, _listId, subscribers));
        }