Ejemplo n.º 1
0
        /// <summary>Updates the existing person.</summary>
        /// <param name="id">The ID.</param>
        /// <param name="value">The person.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <exception cref="SwaggerException">A server side error occurred.</exception>
        public async Task<string> PutAsync(long id, Person value, CancellationToken cancellationToken)
        {
            var url = string.Format("{0}/{1}?", BaseUrl, "api/Persons/Put/{id}");

            url = url.Replace("{id}", id.ToString());

            var client = new HttpClient();
            PrepareRequest(client);

            var content = new StringContent(JsonConvert.SerializeObject(value));
            content.Headers.ContentType.MediaType = "application/json";

            var response = await client.PutAsync(url, content, cancellationToken).ConfigureAwait(false);
            ProcessResponse(client, response);
            var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false); 
            var status = ((int)response.StatusCode).ToString();
            if (status == "204") 
            {
                try
                {
                    return JsonConvert.DeserializeObject<string>(responseData);		
                } 
                catch (Exception exception) 
                {
                    throw new SwaggerException("Could not deserialize the response body.", response.StatusCode, exception);
                }
            }
            else
            {
            }

            throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response.StatusCode + ").", response.StatusCode, null);
        }
Ejemplo n.º 2
0
 /// <summary>Updates the existing person.</summary>
 /// <param name="id">The ID.</param>
 /// <param name="value">The person.</param>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public Task<string> PutAsync(long id, Person value)
 {
     return PutAsync(id, value, CancellationToken.None);
 }
Ejemplo n.º 3
0
        /// <exception cref="SwaggerException">A server side error occurred.</exception>
        public async Task<string> PostAsync(Person request )
        {
            var url = string.Format("{0}/{1}?", BaseUrl, "api/Persons/Post");

            var client = new HttpClient();
            PrepareRequest(client);

            var content = new StringContent(JsonConvert.SerializeObject(request));

            var response = await client.PostAsync(url, content);
            ProcessResponse(client, response);
            var responseData = await response.Content.ReadAsStringAsync(); 
            var status = response.StatusCode.ToString();
            if (status == "200") {
                return JsonConvert.DeserializeObject<string>(responseData);		
            }

            throw new SwaggerException("The response was not expected.", response.StatusCode, null);
        }
Ejemplo n.º 4
0
 /// <summary>Creates a new person.</summary>
 /// <param name="value">The person.</param>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public Task<string> PostAsync(Person value)
 {
     return PostAsync(value, CancellationToken.None);
 }
Ejemplo n.º 5
0
        /// <summary>Updates the existing person.</summary>
        /// <param name="id">The ID.</param>
        /// <param name="value">The person.</param>
        /// <exception cref="SwaggerException">A server side error occurred.</exception>
        public async Task<string> PutAsync(long id, Person value )
        {
            var url = string.Format("{0}/{1}?", BaseUrl, "api/Persons/Put/{id}");

            url = url.Replace("{id}", id.ToString());

            var client = new HttpClient();
            PrepareRequest(client);

            var content = new StringContent(JsonConvert.SerializeObject(value));

            var response = await client.PutAsync(url, content);
            ProcessResponse(client, response);
            var responseData = await response.Content.ReadAsStringAsync(); 
            var status = response.StatusCode.ToString();
            if (status == "200") 
            {
                try
                {
                    return JsonConvert.DeserializeObject<string>(responseData);		
                } 
                catch (Exception exception) 
                {
                    throw new SwaggerException("Could not deserialize the response body.", response.StatusCode, exception);
                }
            }
            else
            {
            }

            throw new SwaggerException("The response was not expected.", response.StatusCode, null);
        }