示例#1
0
        public async Task <ZsCoupon> UpdateAsync(string apiBaseUrl, string authToken, string organizationId, string code, ZsCouponUpdate updateInput)
        {
            apiBaseUrl.CheckConfigApiBaseUrl();
            authToken.CheckConfigAuthToken();
            organizationId.CheckConfigOrganizationId();

            if (updateInput == null)
            {
                throw new ArgumentNullException("updateInput");
            }

            if (string.IsNullOrWhiteSpace(code))
            {
                throw new ArgumentNullException("Coupon code is required");
            }

            var validationResult = updateInput.Validate();

            if (!string.IsNullOrWhiteSpace(validationResult))
            {
                throw new ArgumentException(validationResult);
            }

            using (var httpClient = new HttpClient())
            {
                httpClient.Configure(apiBaseUrl, organizationId, authToken);
                var updateJson = JsonConvert.SerializeObject(
                    updateInput,
                    Formatting.None,
                    new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
                var content = new StringContent(
                    updateJson,
                    Encoding.UTF8,
                    "application/json");
                var response = await httpClient.PutAsync(string.Format(CultureInfo.InvariantCulture, ApiResources.ZsPutCoupon, code), content);

                var processResult = await response.ProcessResponse <ZsCouponJson>();

                if (null != processResult.Error)
                {
                    throw processResult.Error;
                }

                return(processResult.Data.Coupon);
            }
        }
示例#2
0
 public async Task <ZsCoupon> UpdateAsync(string code, ZsCouponUpdate updateInput)
 {
     this.client.Configuration.CheckConfig();
     return(await this.UpdateAsync(this.client.Configuration.ApiBaseUrl, this.client.Configuration.AuthToken, this.client.Configuration.OrganizationId, code, updateInput));
 }