Exemplo n.º 1
0
 public async Task <ZsProduct> CreateAsync(ZsProductInput createInput)
 {
     this.client.Configuration.CheckConfig();
     return(await this.CreateAsync(this.client.Configuration.ApiBaseUrl, this.client.Configuration.AuthToken, this.client.Configuration.OrganizationId, createInput));
 }
Exemplo n.º 2
0
 public async Task <ZsProduct> UpdateAsync(string id, ZsProductInput updateInput)
 {
     this.client.Configuration.CheckConfig();
     return(await this.UpdateAsync(this.client.Configuration.ApiBaseUrl, this.client.Configuration.AuthToken, this.client.Configuration.OrganizationId, id, updateInput));
 }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
            }
        }