示例#1
0
 /// <summary>
 /// Updates an existing communication way for a contact from the sevDesk API.
 /// </summary>
 /// <param name="id">The ID of the communication way.</param>
 /// <param name="options">The options that contain the information about the communication way.</param>
 /// <exception cref="InvalidOperationException">If the API could not be reached or the token is not valid, an <see cref="InvalidOperationException" /> is thrown.</exception>
 public async Task UpdateCommunicationWayAsync(string id, CommunicationWayOptions options)
 {
     try
     {
         // Sends an HTTP request to endpoint
         HttpResponseMessage response = await httpClient.PutAsync($"{this.apiUri}/CommunicationWay/{id}?token={this.Token}", new FormUrlEncodedContent(new List <KeyValuePair <string, string> >
         {
             new KeyValuePair <string, string>("value", options.Value),
             new KeyValuePair <string, string>("key[id]", options.KindId),
             new KeyValuePair <string, string>("key[objectName]", "CommunicationWayKey")
         }));
     }
     catch (Exception e)
     {
         throw new InvalidOperationException(e.Message, e);
     }
 }
示例#2
0
        /// <summary>
        /// Creates a new communication way for a contact from the sevDesk API.
        /// </summary>
        /// <param name="id">The ID of the contact.</param>
        /// <param name="options">The options that contain the information about the communication way.</param>
        /// <exception cref="InvalidOperationException">If the API could not be reached or the token is not valid, an <see cref="InvalidOperationException" /> is thrown.</exception>
        /// <returns>Returns the ID of the created communication way.</returns>
        public async Task <string> CreateCommunicationWayAsync(string id, CommunicationWayOptions options)
        {
            try
            {
                // Gets the appriopriate endpoint
                string endpoint = null;
                if (options is EmailAddressOptions)
                {
                    endpoint = "addEmail";
                }
                if (options is PhoneNumberOptions)
                {
                    endpoint = "addPhone";
                }
                if (options is WebsiteOptions)
                {
                    endpoint = "addWeb";
                }
                if (options is MobilePhoneNumberOptions)
                {
                    endpoint = "addMobile";
                }

                // Sends an HTTP request to endpoint
                HttpResponseMessage response = await httpClient.PostAsync($"{this.apiUri}/Contact/{id}/{endpoint}?token={this.Token}", new FormUrlEncodedContent(new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("value", options.Value),
                    new KeyValuePair <string, string>("key", options.KindId)
                }));

                // Returns the result
                return(JsonConvert.DeserializeObject <Result <Models.CommunicationWays.CommunicationWay> >(await response.Content.ReadAsStringAsync()).objects.id);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(e.Message, e);
            }
        }