private async Task UpdateInventoryAsync(Guid itemId, Int32 quantity) { using (ITransaction tx = _stateManager.CreateTransaction()) { // Use the user’s name to look up their data var inventoryDictionary = await _stateManager.GetOrAddAsync <IReliableDictionary <Guid, InventoryItem> >("inventoryDictionary"); var originalItem = await inventoryDictionary.TryGetValueAsync(tx, itemId); if (originalItem.HasValue) { var updatedItem = InventoryItem.CreateCopy(originalItem.Value); updatedItem.InventoryCount = updatedItem.InventoryCount + quantity; await inventoryDictionary.TryUpdateAsync(tx, itemId, updatedItem, originalItem.Value); await tx.CommitAsync(); } } }