Пример #1
0
        private bool HandleChangesForLocation(StockByLocationV2 locationGroup, List <ArticleCheckpointV2> checkpoints, StockByLocationV2 location)
        {
            var changesHappened = false;

            foreach (var checkpoint in checkpoints)
            {
                var newCheckpoint =
                    locationGroup.Checkpoints.FirstOrDefault(x => x.ArticleId == checkpoint.ArticleId);

                if (newCheckpoint != null)
                {
                    checkpoint.Quantity += newCheckpoint.Quantity;
                    changesHappened      = true;
                }

                locationGroup.Checkpoints.Remove(newCheckpoint);
            }

            if (locationGroup.Checkpoints.Count > 0)
            {
                location.Checkpoints.AddRange(locationGroup.Checkpoints);
                changesHappened = true;
            }

            return(changesHappened);
        }
Пример #2
0
        public async Task CalculateInventoryOnStorageLocations(StockByLocationV2 locationGroup)
        {
            var locationId = locationGroup.LocationId;

            var result = await GetStockDocument <StockByLocationV2>(_stockPerLocationContainer, locationId);

            if (result is null)
            {
                await CreateStockByLocations(_stockPerLocationContainer, locationId, locationGroup);

                return;
            }

            await UpdateStockByLocation(result, locationGroup, _stockPerLocationContainer);
        }
Пример #3
0
        private async Task CreateStockByLocations(Container container, string locationId, StockByLocationV2 locationGroup)
        {
            var storageLocationStock = new StockByLocationV2
            {
                Id           = locationId,
                LocationId   = locationId,
                LocationType = locationGroup.LocationType,
                Checkpoints  = locationGroup.Checkpoints
            };

            ItemRequestOptions requestOptions = new ItemRequestOptions {
                EnableContentResponseOnWrite = false
            };

            var response = await container.CreateItemAsync(storageLocationStock,
                                                           new PartitionKey(locationId), requestOptions);

            Console.WriteLine($"\nRequest Charge for creating storage location: {response.RequestCharge}\n");
        }
Пример #4
0
        private async Task UpdateStockByLocation(ItemResponse <StockByLocationV2> result, StockByLocationV2 locationGroup, Container container)
        {
            bool changesHappened;
            var  locationId = locationGroup.LocationId;

            var location = result.Resource;

            var checkpoints = location.Checkpoints;

            if (checkpoints.Count == 0)
            {
                location.Checkpoints.AddRange(locationGroup.Checkpoints);
                changesHappened = true;
            }
            else
            {
                changesHappened = HandleChangesForLocation(locationGroup, checkpoints, location);
            }

            if (changesHappened)
            {
                var responseForUpdate = await container.ReplaceItemAsync(
                    partitionKey : new PartitionKey(locationId),
                    id : locationId,
                    item : location);

                Console.WriteLine($"\nRequest Charge for updating storage location: {responseForUpdate.RequestCharge}\n");
            }
            else
            {
                Console.WriteLine($"\nNo changes were made\n");
            }
        }