public async Task <T> GetItemAsync <T>(CosmosDbContainers containerName, string id) { Container container = SetupContainer(containerName); try { ItemResponse <T> response = await container.ReadItemAsync <T>(id, new PartitionKey(id)).ConfigureAwait(false); return(response.Resource); } catch (CosmosException ex) when(ex.StatusCode == System.Net.HttpStatusCode.NotFound) { return(default);
public async Task AddItemsAsync <T>(CosmosDbContainers containerName, List <T> items) { Container conatiner = SetupContainer(containerName); List <Task> TaskList = new List <Task>() { }; foreach (T item in items) { Task <ItemResponse <T> > LastTask = conatiner.CreateItemAsync <T>(item); TaskList.Add(LastTask); } await Task.WhenAll(TaskList.Where(t => t != null)).ConfigureAwait(false); }
public async Task DeleteItemAsync <T>(CosmosDbContainers containerName, string id) { Container conatiner = SetupContainer(containerName); await conatiner.DeleteItemAsync <T>(id, new PartitionKey(id)).ConfigureAwait(false); }
public async Task AddItemAsync <T>(CosmosDbContainers containerName, T item) { Container conatiner = SetupContainer(containerName); await conatiner.CreateItemAsync <T>(item).ConfigureAwait(false); }
private Container SetupContainer(CosmosDbContainers containerName) { return(dbClient.GetContainer(databaseName, containerName.ToString())); }