public async Task <ZsProduct> CreateAsync(string apiBaseUrl, string authToken, string organizationId, ZsProductInput createInput) { apiBaseUrl.CheckConfigApiBaseUrl(); authToken.CheckConfigAuthToken(); organizationId.CheckConfigOrganizationId(); if (createInput == null) { throw new ArgumentNullException("createInput"); } var validationResult = createInput.Validate(); if (!string.IsNullOrWhiteSpace(validationResult)) { throw new ArgumentException(validationResult); } using (var httpClient = new HttpClient()) { httpClient.Configure(apiBaseUrl, organizationId, authToken); var content = new StringContent( JsonConvert.SerializeObject( createInput, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync(ApiResources.ZsPostProduct, content); var processResult = await response.ProcessResponse <ZsProductJson>(); if (null != processResult.Error) { throw processResult.Error; } return(processResult.Data.Product); } }
public async Task <ZsProduct> UpdateAsync(string apiBaseUrl, string authToken, string organizationId, string id, ZsProductInput updateInput) { apiBaseUrl.CheckConfigApiBaseUrl(); authToken.CheckConfigAuthToken(); organizationId.CheckConfigOrganizationId(); if (updateInput == null) { throw new ArgumentNullException("updateInput"); } if (string.IsNullOrEmpty(id) || id == string.Empty) { throw new ArgumentNullException("id"); } var validationResult = updateInput.Validate(); if (!string.IsNullOrWhiteSpace(validationResult)) { throw new ArgumentException(validationResult); } using (var httpClient = new HttpClient()) { httpClient.Configure(apiBaseUrl, organizationId, authToken); var content = new StringContent(JsonConvert.SerializeObject(updateInput), Encoding.UTF8, "application/json"); var response = await httpClient.PutAsync(string.Format(CultureInfo.InvariantCulture, ApiResources.ZsPutProduct, id), content); var processResult = await response.ProcessResponse <ZsProductJson>(); if (null != processResult.Error) { throw processResult.Error; } return(processResult.Data.Product); } }