public InventoryItemStockTransactionBuilder AddInventoryItemStock(long inventoryItemId, string unitOfMeasureCode, decimal unitCost, int quantity) { if (m_inventoryItemStockTransaction == null) { throw new InvalidOperationException("Begin has not been called."); } //if (m_order != null) throw new InvalidOperationException("Cannot add stock when processing order."); var dbInventoryItemStock = new InventoryItemStock() { InventoryItemId = inventoryItemId, UnitOfMeasureCode = unitOfMeasureCode, UnitCost = unitCost, StockDateTimeUtc = m_utcNow, OriginalQuantity = quantity, CurrentQuantity = quantity, }; _ = m_ctx.InventoryItemStocks.Add(dbInventoryItemStock); var dbInventoryItemStockTransactionItem = new InventoryItemStockTransactionItem() { InventoryItemStock = dbInventoryItemStock, InventoryItemStockTransaction = m_inventoryItemStockTransaction, Quantity = quantity, Cost = unitCost * quantity, }; _ = m_ctx.InventoryItemStockTransactionItems.Add(dbInventoryItemStockTransactionItem); dbInventoryItemStockTransactionItem.InventoryItemStock.InventoryItem.Quantity += quantity; return(this); }
public void AddConsumable(string consumableType, int consumableCount) { if (!consumableInventory.inventoryMap.ContainsKey(consumableType)) { consumableInventory.inventoryMap[consumableType] = new InventoryItemStock(); } InventoryItemStock inventoryItemStock = consumableInventory.inventoryMap[consumableType]; inventoryItemStock.itemCount += consumableCount; }
public void UseConsumable(string consumableType) { ConsumableInventory consumableInventory = default(ConsumableInventory); consumableInventory.inventoryMap = new Dictionary <string, InventoryItemStock>(this.consumableInventory.inventoryMap); InventoryItemStock inventoryItemStock = consumableInventory.inventoryMap[consumableType]; inventoryItemStock.DecrementCount(); ConsumableInventory = consumableInventory; }