예제 #1
0
        /// <summary>
        /// Checks if any of the suppliers has Article in specified price range in stock
        /// </summary>
        /// <param name="id">Id of the article</param>
        /// <param name="maxExpectedPrice">Max price of the Article</param>
        /// <param name="suppliers">List of suppliers available</param>
        /// <param name="index">recursion index</param>
        /// <returns>Article if found, null if not existing</returns>
        private Article FindArticle(int id, int maxExpectedPrice, ISupplier[] suppliers, int index = 0)
        {
            if (suppliers.Length == index)
            {
                logger.Debug("No more suppliers to check");
                return(null);
            }

            ISupplier supplier = suppliers[index];

            logger.Debug($"Checking supplier [Name = {supplier.ToString()}]");
            var articleExists = supplier.ArticleInInventory(id);

            if (articleExists)
            {
                Article tempArticle = supplier.GetArticle(id);
                if (maxExpectedPrice >= tempArticle.ArticlePrice)
                {
                    return(tempArticle);
                }
            }

            logger.Debug($"Supplier [Name = {supplier.ToString()}]: Article not found, searching at another supplier");

            return(FindArticle(id, maxExpectedPrice, suppliers, index + 1));
        }
예제 #2
0
        public Article Order(int id, int maxExpectedPrice)
        {
            if (_supplier.ArticleInInventory(id))
            {
                Article article = _supplier.GetArticle(id);
                if (article.ArticlePrice < maxExpectedPrice)
                {
                    article.SupplierId = _supplier.Id;
                    return(article);
                }
            }

            return(Successor.Order(id, maxExpectedPrice));
        }