예제 #1
0
        /// <summary>
        /// Add or edit a contact based on their email address. Instead of calling contact_view to check if the contact exists,
        /// and then calling contact_add or contact_edit, you can make just one call and include only the information you want added or updated.
        /// </summary>
        /// <param name="basicContactInfo"></param>
        /// <param name="contactLists"></param>
        /// <returns><see cref="ContactSyncResponse"/></returns>
        public ContactSyncResponse SyncContact(BasicContactInfo basicContactInfo, IEnumerable <BasicContactList> contactLists)
        {
            var postData = new Dictionary <string, string>
            {
                { "email", basicContactInfo.Email },
                { "first_name", basicContactInfo.FirstName ?? string.Empty },
                { "last_name", basicContactInfo.LastName ?? string.Empty },
                { "phone", basicContactInfo.Phone ?? string.Empty },
                { "orgname", basicContactInfo.OrganizationName ?? string.Empty },
                { "form", basicContactInfo.FormId.ToString() ?? string.Empty },
            };

            if (basicContactInfo.Tags != null && basicContactInfo.Tags.Any())
            {
                postData.Add("tags", string.Join(",", basicContactInfo.Tags));
            }

            foreach (var contactList in contactLists)
            {
                postData.Add(
                    string.Format("p[{0}]", contactList.Id), contactList.Id.ToString());

                postData.Add(
                    string.Format("status[{0}]", contactList.Id),
                    contactList.Status.ToString("D"));

                postData.Add(
                    string.Format("noresponders[{0}]", contactList.Id),
                    Convert.ToInt32(contactList.Noresponders).ToString());

                postData.Add(
                    string.Format("sdate[{0}]", contactList.Id),
                    contactList.SubscribeDate);

                postData.Add(
                    string.Format("instantresponders[{0}]", contactList.Id),
                    Convert.ToInt32(contactList.InstantResponders).ToString());

                postData.Add(
                    string.Format("lastmessage[{0}]", contactList.Id),
                    Convert.ToInt32(contactList.LastMessage).ToString());
            }

            if (basicContactInfo.Fields != null && basicContactInfo.Fields.Any())
            {
                foreach (var field in basicContactInfo.Fields)
                {
                    postData.Add(
                        string.Format("field[{0},0]", field.Id != null ? field.Id.ToString() : field.Name),
                        field.Value);
                }
            }

            var jsonResponse = SendRequest("contact_sync", null, postData);

            return(JsonConvert.DeserializeObject <ContactSyncResponse>(jsonResponse));
        }
예제 #2
0
        public Dictionary <string, object> SyncContact(BasicContactInfo basicContactInfo, IEnumerable <BasicContactList> contactLists)
        {
            Dictionary <string, string> postParameters = new Dictionary <string, string>()
            {
                {
                    "email",
                    basicContactInfo.Email
                },
                {
                    "first_name",
                    basicContactInfo.FirstName
                },
                {
                    "last_name",
                    basicContactInfo.LastName
                },
                {
                    "phone",
                    basicContactInfo.Phone
                },
                {
                    "orgname",
                    basicContactInfo.OrganizationName
                },
                {
                    "form",
                    basicContactInfo.FormId.ToString()
                },
                {
                    "tags",
                    string.Join(",", (IEnumerable <string>)basicContactInfo.Tags)
                }
            };

            foreach (BasicContactList contactList in contactLists)
            {
                postParameters.Add(string.Format("p[{0}]", (object)contactList.Id), contactList.Id.ToString());
                postParameters.Add(string.Format("status[{0}]", (object)contactList.Id), contactList.Status.ToString("D"));
                postParameters.Add(string.Format("noresponders[{0}]", (object)contactList.Id), Convert.ToInt32(contactList.Noresponders).ToString());
                postParameters.Add(string.Format("sdate[{0}]", (object)contactList.Id), contactList.SubscribeDate);
                postParameters.Add(string.Format("instantresponders[{0}]", (object)contactList.Id), Convert.ToInt32(contactList.InstantResponders).ToString());
                postParameters.Add(string.Format("lastmessage[{0}]", (object)contactList.Id), Convert.ToInt32(contactList.LastMessage).ToString());
            }
            if (basicContactInfo.Fields != null)
            {
                foreach (Field field in basicContactInfo.Fields)
                {
                    postParameters.Add(string.Format("field[{0},0]", field.Id.HasValue ? (object)field.Id.ToString() : (object)field.Name), field.Value);
                }
            }
            return(this.service.SendRequest("contact_sync", (Dictionary <string, string>)null, postParameters));
        }
예제 #3
0
        public bool AddContact(BasicContactInfo basicContactInfo, IEnumerable <BasicContactList> contactLists)
        {
            Dictionary <string, string> postParameters = new Dictionary <string, string>()
            {
                {
                    "email",
                    basicContactInfo.Email
                },
                {
                    "first_name",
                    basicContactInfo.FirstName
                },
                {
                    "last_name",
                    basicContactInfo.LastName
                },
                {
                    "phone",
                    basicContactInfo.Phone
                },
                {
                    "orgname",
                    basicContactInfo.OrganizationName
                },
                {
                    "tags",
                    string.Join(",", (IEnumerable <string>)basicContactInfo.Tags)
                }
            };

            foreach (BasicContactList contactList in contactLists)
            {
                postParameters.Add(string.Format("p[{0}]", (object)contactList.Id), contactList.Id.ToString());
                postParameters.Add(string.Format("status[{0}]", (object)contactList.Id), ((int)contactList.Status).ToString());
            }
            return(this.service.IsRequestSuccessfull((IReadOnlyDictionary <string, object>) this.service.SendRequest("contact_add", (Dictionary <string, string>)null, postParameters)));
        }