public static RealTimeInventory InitializeFromStorage(this RealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string id)
        {
            var initTask = inventoryStorage.ReadInventoryAsync(id);

            Task.WaitAll(initTask);
            var inventory = initTask.Result.Result;

            if (!initTask.Result.IsSuccessful)
            {
                throw initTask.Result.Errors.Flatten();
            }
            return(new RealTimeInventory(id, inventory.Quantity, inventory.Reserved, inventory.Holds));
        }
        public static async Task <OperationResult <IRealTimeInventory> > ReadInventoryFromStorageAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId)
        {
            try
            {
                if (string.IsNullOrEmpty(productId))
                {
                    return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.NO_PRODUCT_ID_SPECIFIED, realTimeInventory, 0).ToFailedOperationResult(realTimeInventory));
                }
                var result = await inventoryStorage.ReadInventoryAsync(productId);

                return(result.Result.ToSuccessOperationResult());
            }
            catch (Exception e)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_READ_INV, realTimeInventory, 0, e).ToFailedOperationResult());
            }
        }