コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
                }
            }
        }