public static async Task <Document> TryCreateDocumentAsync(this IChangeFeedDocumentClient client, string collectionLink, object document) { try { IResourceResponse <Document> response = await client.CreateDocumentAsync(collectionLink, document).ConfigureAwait(false); return(response.Resource); } catch (DocumentClientException ex) when(ex.StatusCode == HttpStatusCode.Conflict) { return(null); // Ignore -- document already exists. } }
public static async Task <bool> TryCreateDocumentAsync(this IChangeFeedDocumentClient client, string collectionLink, object document) { try { await client.CreateDocumentAsync(collectionLink, document).ConfigureAwait(false); return(true); } catch (DocumentClientException ex) { if (ex.StatusCode != HttpStatusCode.Conflict) { throw; } } return(false); }
public async Task <IResourceResponse <Document> > CreateDocumentAsync(string collectionLink, object document) { return(await _inner.CreateDocumentAsync(collectionLink, document)); }