async Task CreateFamilyDocumentIfNotExists(DocumentClient client, string databaseName, string collectionName, Family family) { try { await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, family.Id)); } catch (DocumentClientException e) { if (e.StatusCode == HttpStatusCode.NotFound) { await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), family); } else { // Rethrow throw; } } }
public class Family { [JsonProperty(PropertyName = "id")] public string Id { get; set; } public string LastName { get; set; } public Parent[] Parents { get; set; } public Child[] Children { get; set; } public Address Address { get; set; } public bool IsRegistered { get; set; } public override string ToString() { return JsonConvert.SerializeObject(this); } } public class Parent { public string FamilyName { get; set; } public string FirstName { get; set; } } public class Child { public string FamilyName { get; set; } public string FirstName { get; set; } public string Gender { get; set; } public int Grade { get; set; } public Pet[] Pets { get; set; } } public class Pet { public string GivenName { get; set; } } public class Address { public string State { get; set; } public string County { get; set; } public string City { get; set; } }