예제 #1
0
        /// <summary>
        /// Update a price of a product.
        ///   The price of the product will be update to new price that user enters.
        /// </summary>
        /// <param name="numberOfCatalogues">The number of catalogues created.</param>
        private static void UpdatePrice(ref int numberOfCatalogues)
        {
            if (numberOfCatalogues == 0)
            {
                Console.WriteLine("No catalogues exist. Please create a catalogue first.");
                return;
            }

            ProductCatalogue cata = SelectCatalogue(numberOfCatalogues);

            // Show all products in the catalogue and products in it.
            ShowProductNamesAndPrice(cata);
            if (cata.NumberOfProducts == 0)
            {
                return;
            }

            int index = SelectProduct(cata.NumberOfProducts);
            //show a product that a user selected
            ProductData data = cata.GetProduct(index - 1);

            Console.Write("You have selected {0}.", data.ProductName);
            Console.WriteLine("The current retail price is {0:c2}.", data.RetailPrice);
            //update the price
            data.RetailPrice = InputHelper.GetPositiveDoubleFromUser("Please enter the new price: ");

            Console.WriteLine();
        }
예제 #2
0
 /// <summary>
 /// Show all products in the catalog.
 /// </summary>
 /// <param name="cata">Product catalog.</param>
 private static void ShowProductNamesAndPrice(ProductCatalogue cata)
 {
     if (cata == null || cata.NumberOfProducts == 0)
     {
         Console.WriteLine("No products exist.");
         return;
     }
     for (int i = 0; i < cata.NumberOfProducts; i++)
     {
         ProductData data = cata.GetProduct(i);
         //product number starts from 1, thus "+1"
         Console.WriteLine("{0}. {1}: {2:c2}", (i + 1), data.ProductName, data.RetailPrice);
     }
 }