Exemple #1
0
        /// <summary>
        /// sell product
        /// </summary>
        private void Sell()
        {
            // get the product type the user wants to sell
            Product.ProductType productType = _consoleView.DisplaySellProducts(_salesperson);
            int numberOfUnits = 0;

            // foreach loop to find the existing product
            foreach (Product item in _salesperson.CurrentStock)
            {
                // if product type is found it prompts the user for number of products
                // and subtracts them from the product
                if (item.Type == productType && productType != Product.ProductType.None)
                {
                    numberOfUnits = _consoleView.GetNumberOfUnitsToSell();
                    item.SubtractProducts(numberOfUnits);

                    // if more products are sold than exist in inventory
                    // backorder notification is displayed to the user
                    if (item.OnBackorder)
                    {
                        _consoleView.DisplayBackorderNotification(item, numberOfUnits);
                    }

                    // find the product in the salesIndo list and update the number of units sold
                    foreach (Product product in city.SalesInfo)
                    {
                        if (productType == product.Type)
                        {
                            product.SellProducts(numberOfUnits);
                        }
                    }
                }
            }
        }