Exemplo n.º 1
0
        public virtual async Task <bool> TryIncreaseInventoryAsync(ProductInventory productInventory, int quantity, bool decreaseSold)
        {
            if (quantity < 0)
            {
                return(false);
            }

            var originalInventory = productInventory.Inventory;

            if (!productInventory.TryIncreaseInventory(quantity, decreaseSold))
            {
                return(false);
            }

            using var uow = _unitOfWorkManager.Begin(isTransactional: true);

            await _productInventoryRepository.UpdateAsync(productInventory, true);

            PublishInventoryChangedEventOnUowCompleted(uow, productInventory.ProductId, productInventory.ProductSkuId,
                                                       originalInventory, productInventory.Inventory, productInventory.Sold);

            await uow.CompleteAsync();

            return(true);
        }
        public virtual async Task <bool> TryIncreaseInventoryAsync(ProductInventory productInventory, int quantity, bool decreaseSold)
        {
            if (quantity < 0)
            {
                return(false);
            }

            var originalInventory = productInventory.Inventory;

            if (!productInventory.TryIncreaseInventory(quantity, decreaseSold))
            {
                return(false);
            }

            await _productInventoryRepository.UpdateAsync(productInventory, true);

            PublishInventoryChangedEventOnUowCompleted(productInventory.ProductId, productInventory.ProductSkuId,
                                                       originalInventory, productInventory.Inventory, productInventory.Sold);

            return(true);
        }
Exemplo n.º 3
0
        protected virtual async Task <bool> TryIncreaseInventoryAsync(InventoryQueryModel model,
                                                                      ProductInventory productInventory, int quantity, bool decreaseSold)
        {
            if (quantity < 0)
            {
                return(false);
            }

            var originalInventory = productInventory.Inventory;

            if (!productInventory.TryIncreaseInventory(quantity, decreaseSold))
            {
                return(false);
            }

            await _productInventoryRepository.UpdateAsync(productInventory, true);

            await PublishInventoryChangedEventAsync(model.TenantId, model.StoreId,
                                                    productInventory.ProductId, productInventory.ProductSkuId, originalInventory,
                                                    productInventory.Inventory, productInventory.Sold);

            return(true);
        }