Пример #1
0
 public async Task <ZsContactPerson> CreateAsync(string customerId, ZsContactPersonInput createInput)
 {
     this.client.Configuration.CheckConfig();
     return(await this.CreateAsync(this.client.Configuration.ApiBaseUrl, this.client.Configuration.AuthToken, this.client.Configuration.OrganizationId, customerId, createInput));
 }
Пример #2
0
        public async Task <ZsContactPerson> UpdateAsync(string apiBaseUrl, string authToken, string organizationId, string customerId, string contactPersonId, ZsContactPersonInput updateInput)
        {
            apiBaseUrl.CheckConfigApiBaseUrl();
            authToken.CheckConfigAuthToken();
            organizationId.CheckConfigOrganizationId();

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

            if (string.IsNullOrWhiteSpace(customerId))
            {
                throw new ArgumentNullException("Customer id is required");
            }

            if (string.IsNullOrWhiteSpace(contactPersonId))
            {
                throw new ArgumentNullException("Contact person id 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.ZsPutContactPerson, customerId, contactPersonId), content);

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

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

                return(processResult.Data.ContactPerson);
            }
        }