public override void AdjustStock(StockQuantity quantity) { if (quantity is VolumeStockQuantity) { VolumeStockQuantity quan = quantity as VolumeStockQuantity; _StoredStock += quan.Quantity; return; } }
public override bool Purchase(StockQuantity quantity, out Item item) { VolumeStockQuantity quan = quantity as VolumeStockQuantity; double targetQuantity = 1; if (quantity != null) { if (quan.Quantity > _ShelfStock) { targetQuantity = _ShelfStock; } else if (_ShelfStock >= quan.Quantity) { targetQuantity = quan.Quantity; } } else if (quantity == null) { if (_ShelfStock > 0) { targetQuantity = _DefaultPurchase; } else if (_ShelfStock - _DefaultPurchase <= 0) { targetQuantity = 0; } else if (_ShelfStock - quan.Quantity <= 0) { targetQuantity = 0; } } // Calculations _ShelfStock -= targetQuantity; if (targetQuantity == 0) { item = null; return(false); } else { item = new Item((1), (Line.Description + " " + targetQuantity + " kg"), (targetQuantity)); } return(true); /// old code - using for reference in the future - please ignore /* bool QuantityIsVolume = false; * VolumeStockQuantity quan = quantity as VolumeStockQuantity; * if (quantity is VolumeStockQuantity) * { * QuantityIsVolume = true; * } * else if (quantity is DiscreteStockQuantity || quantity == null) * { * QuantityIsVolume = false; * } * * if (QuantityIsVolume == true) * { * if (quan.Quantity > _ShelfStock) * { * double maxshelf = _ShelfStock; * _ShelfStock -= maxshelf; * } * else if (_ShelfStock >= quan.Quantity) * { * _ShelfStock -= quan.Quantity; * } * } * else if (QuantityIsVolume == false) * { * if (_ShelfStock > _DefaultPurchase) * { * _ShelfStock -= _DefaultPurchase; * } * } * * if (quantity == null) * { * * item = null; * return false; * } * else * item = new Item((1), (Line.Description + " " + quan.Quantity + " kg"), (quan.Quantity)); * return true; */ }