public RegionStockItem ApplyStockChanges(WarehouseAvailableStockItem warehouseAvailableAvailableStock) { if (warehouseAvailableAvailableStock == null) { throw new ArgumentNullException(); } if (_warehouseAvailableStocks != null) { var index = _warehouseAvailableStocks.FindIndex( (x) => (x.Sku == warehouseAvailableAvailableStock.Sku && x.FulfilmentCentre == warehouseAvailableAvailableStock.FulfilmentCentre)); if (index > -1) { _warehouseAvailableStocks.RemoveAt(index); _warehouseAvailableStocks.Insert(index, warehouseAvailableAvailableStock); } else { _warehouseAvailableStocks.Add(warehouseAvailableAvailableStock); } } else { _warehouseAvailableStocks = new List <WarehouseAvailableStockItem> { warehouseAvailableAvailableStock }; } Quantity = WarehouseAvailableStocks.Sum(x => x.Pickable - (x.Allocated + x.Reserved)); if (Status == null) { Status = new RegionStockItemStatus(10, StockStatus.OutOfStock); } Status.Evaluate(Quantity); Version = warehouseAvailableAvailableStock.Version; return(this); }
public WarehouseAvailableStockItem ApplyStockChanges(WarehouseAvailableStockItem warehouseAvailableStock) { if (Sku.Equals(warehouseAvailableStock.Sku, StringComparison.OrdinalIgnoreCase) && FulfilmentCentre.Equals(warehouseAvailableStock.FulfilmentCentre, StringComparison.OrdinalIgnoreCase)) { if (Version > warehouseAvailableStock.Version) { throw new StaleWarehouseAvailableStockChangedException( $"Stale Warehouse Available Stock Change encountered for SKU {warehouseAvailableStock.Sku} in Warehouse {warehouseAvailableStock.FulfilmentCentre}"); } Pickable = warehouseAvailableStock.Pickable; Reserved = warehouseAvailableStock.Reserved; Allocated = warehouseAvailableStock.Allocated; Version = warehouseAvailableStock.Version; } return(this); }
public void ApplyStockChanges(WarehouseAvailableStockItem warehouseAvailableStock) { var availableStock = WarehouseAvailableStocks.SingleOrDefault( x => x.Sku.Equals(warehouseAvailableStock.Sku, StringComparison.OrdinalIgnoreCase) && x.FulfilmentCentre.Equals(warehouseAvailableStock.FulfilmentCentre, StringComparison.OrdinalIgnoreCase)); if (availableStock == null) { WarehouseAvailableStocks.Add(warehouseAvailableStock); } else { availableStock.ApplyStockChanges(warehouseAvailableStock); } ApplyRegionStockChanges(warehouseAvailableStock); }
private void ApplyRegionStockChanges(WarehouseAvailableStockItem warehouseAvailableStock) { var wrs = _warehouseRegions.Where(x => x.WarehouseId == warehouseAvailableStock.FulfilmentCentre); foreach (var wr in wrs) { var rs = RegionStocks.SingleOrDefault(x => x.Region == wr.RegionId); // get regions affected - map regions to warehouse if (rs == null) { rs = new RegionStockItem(wr.RegionId, 0, new RegionStockItemStatus(LowInStockThreshold, StockStatus.OutOfStock), new WarehouseAvailableStockItem[] { }, DateTime.UtcNow); rs.ApplyStockChanges(warehouseAvailableStock); RegionStocks.Add(rs); } else { rs.ApplyStockChanges(warehouseAvailableStock); } } }