Example #1
0
        /// <summary>
        /// Update contact details for a specific contact.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="contact">Contact to be updated.</param>
        /// <param name="actionByVisitor">Set to true if action by visitor.</param>
        /// <returns>Returns the updated contact.</returns>
        public Contact UpdateContact(string accessToken, string apiKey, Contact contact, bool actionByVisitor)
        {
            Contact updateContact = null;
            string url = String.Concat(Config.Endpoints.BaseUrl, String.Format(Config.Endpoints.Contact, contact.Id), actionByVisitor ? String.Format("?action_by={0}", ActionBy.ActionByVisitor) : null);
            string json = contact.ToJSON();
            CUrlResponse response = RestClient.Put(url, accessToken, apiKey, json);
            if (response.HasData)
            {
                updateContact = Component.FromJSON<Contact>(response.Body);
            }
            else
                if (response.IsError) {
                    throw new CtctException(response.GetErrorMessage());
                }

            return updateContact;
        }
Example #2
0
        /// <summary>
        /// Update contact details for a specific contact.
        /// </summary>
        /// <param name="contact">Contact to be updated.</param>
        /// <param name="actionByVisitor">Set to true if action by visitor.</param>
        /// <returns>Returns the updated contact.</returns>
        public Contact UpdateContact(Contact contact, bool actionByVisitor)
        {
            if (contact == null)
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.ContactOrId);
            }

            if (contact.Id == null)
            {
                throw new CtctException(CTCT.Resources.Errors.UpdateId);
            }
            string url = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.Contact, contact.Id), actionByVisitor ? String.Format("?action_by={0}", ActionBy.ActionByVisitor) : null);
            string json = contact.ToJSON();
            RawApiResponse response = RestClient.Put(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json);
            try
            {
                var updateContact = response.Get<Contact>();
                return updateContact;
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }  
        }