public async Task <CosmosDbResponse <T> > Delete <T>(string partitionKey, string id) { PartitionKey pk = PartitionKey.None; if (!string.IsNullOrWhiteSpace(partitionKey)) { pk = new PartitionKey(partitionKey); } Stopwatch watch = Stopwatch.StartNew(); try { ItemResponse <T> itemResponse = await _container.DeleteItemAsync <T>(id, pk); watch.Stop(); CosmosDbResponse <T> response = itemResponse.ToCosmosDbResponse(watch.Elapsed); return(response); } catch (CosmosException cex) { watch.Stop(); return(cex.ToCosmosDbResponse <T>(watch.Elapsed)); } }
public async Task <CosmosDbResponse <T> > Get <T>(string partitionKey, string id) { PartitionKey pk = PartitionKey.Null; if (!string.IsNullOrWhiteSpace(partitionKey)) { pk = new PartitionKey(partitionKey); } Stopwatch watch = Stopwatch.StartNew(); ItemResponse <T> response = await _container.ReadItemAsync <T>(id, pk); watch.Stop(); CosmosDbResponse <T> result = response.ToCosmosDbResponse(watch.Elapsed); return(result); }
public async Task <CosmosDbResponse <T> > Add <T>(string partitionKey, T entity) { PartitionKey pk = PartitionKey.Null; if (!string.IsNullOrWhiteSpace(partitionKey)) { pk = new PartitionKey(partitionKey); } Stopwatch watch = Stopwatch.StartNew(); ItemResponse <T> response = await _container.CreateItemAsync(entity, pk, new ItemRequestOptions() { IndexingDirective = IndexingDirective.Default }); watch.Stop(); CosmosDbResponse <T> result = response.ToCosmosDbResponse(watch.Elapsed); return(result); }