Esempio n. 1
0
        public virtual void Take(Inventory inventory, long quantity)
        {
            var storedInventory = _storedInventories.First(x => x.Inventory.Id == inventory.Id);

            if (storedInventory == null || storedInventory.Stock < quantity)
            {
                throw new ApplicationException(string.Format(@"Not enough {0} stock stored in {1}", inventory.Name, Name));
            }

            storedInventory.Stock -= quantity;
        }
Esempio n. 2
0
        public void AddTransferItem(Storage from, Storage to, Inventory inventory, long quantity)
        {
            if (from.GetStockOf(inventory) < quantity)
            {
                throw new ApplicationException(string.Format(@"Not enough {0} stock stored in {1}", inventory.Name, from.Name));
            }

            from.Take(inventory, quantity);
            to.Store(inventory, quantity);

            _stockTransferItems.Add(new StockTransferItem(inventory, from, to, quantity));
        }
Esempio n. 3
0
        public virtual void Store(Inventory inventory, long quantity)
        {
            var storedInventory = _storedInventories.FirstOrDefault(x => x.Inventory.Id == inventory.Id);

            if (storedInventory != null)
            {
                storedInventory.Stock += quantity;
            }
            else
            {
                _storedInventories.Add(new StoredInventory(this, inventory, quantity));
            }
        }
Esempio n. 4
0
        public virtual void AddMovementItem(Inventory inventory, Storage storage, long quantity)
        {
            foreach (var stockMovementItem in _stockMovementItems)
            {
                if (stockMovementItem.Inventory == inventory)
                {
                    var tempQty = stockMovementItem.Quantity;

                    _stockMovementItems.Remove(stockMovementItem);

                    quantity += tempQty;
                }
            }

            _stockMovementItems.Add(new StockMovementItem(this, inventory, storage, quantity));
        }
Esempio n. 5
0
        public virtual long GetStockOf(Inventory inventory)
        {
            var storedInventory = _storedInventories.FirstOrDefault(x => x.Inventory.Id == inventory.Id);

            return storedInventory == null ? 0 : storedInventory.Stock;
        }