public async Task <bool> CreateANewContactAsync(CreateANewContactRequestModel model) { string json = JsonConvert.SerializeObject(new ContactBaseModel { Properties = model.GetListOfProperties() }); StringContent stringContent = new StringContent(json, Encoding.Default, "application/json"); var result = await _client.PostAsync("contacts/v1/contact?hapikey=" + APIKey, stringContent); var jsonResponse = await result.Content.ReadAsStringAsync(); if (result.IsSuccessStatusCode) { return(true); } else { var response = JsonConvert.DeserializeObject <BaseModel>(jsonResponse); if (response?.ValidationResults?.Where(v => v.isValid == false).Count() > 0) { throw new ValidationException(response.ValidationResults.Where(v => v.isValid == false).First().message); } else if (response != null && response.Message != null) { throw new Exception(response.Message); } else { throw new Exception("Unkown Error"); } } }
public bool CreateANewContact(CreateANewContactRequestModel model) => CreateANewContactAsync(model).GetAwaiter().GetResult();