Esempio n. 1
0
        private bool HandleChangesForArticles(StockByArticleV2 articleGroup, List <LocationCheckpointV2> checkpoints, StockByArticleV2 article)
        {
            var changesHappened = false;

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

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

                articleGroup.Checkpoints.Remove(newCheckpoint);
            }

            if (articleGroup.Checkpoints.Count > 0)
            {
                article.Checkpoints.AddRange(articleGroup.Checkpoints);
                changesHappened = true;
            }

            return(changesHappened);
        }
Esempio n. 2
0
        public async Task CalculateInventoryForArticles(StockByArticleV2 articleGroup)
        {
            var articleId = articleGroup.ArticleId;

            var result = await GetStockDocument <StockByArticleV2>(_stockPerArticleContainer, articleId);

            if (result is null)
            {
                await CreateStockByArticles(_stockPerArticleContainer, articleId, articleGroup);

                return;
            }

            await UpdateStockByArticles(result, articleGroup, _stockPerArticleContainer);
        }
Esempio n. 3
0
        private async Task CreateStockByArticles(Container container, string articleId, StockByArticleV2 articleGroup)
        {
            var articleStock = new StockByArticleV2
            {
                Id          = articleId,
                ArticleId   = articleId,
                ArticleName = articleGroup.ArticleName,
                Checkpoints = articleGroup.Checkpoints
            };

            ItemRequestOptions requestOptions = new ItemRequestOptions {
                EnableContentResponseOnWrite = false
            };

            var response = await container.CreateItemAsync(articleStock,
                                                           new PartitionKey(articleId), requestOptions);

            Console.WriteLine($"\nRequest Charge for creating storage location: {response.RequestCharge}\n");
        }
Esempio n. 4
0
        private async Task UpdateStockByArticles(ItemResponse <StockByArticleV2> result, StockByArticleV2 articleGroup, Container container)
        {
            bool changesHappened;
            var  articleId = articleGroup.ArticleId;

            var article = result.Resource;

            var checkpoints = article.Checkpoints;

            if (checkpoints.Count == 0)
            {
                article.Checkpoints.AddRange(articleGroup.Checkpoints);
                changesHappened = true;
            }
            else
            {
                changesHappened = HandleChangesForArticles(articleGroup, checkpoints, article);
            }

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

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