예제 #1
0
 public override void ViewStoreProducts(double threshold = 0)
 {
     if (!StoreList.isEmpty())
     {
         if (threshold >= 0)
         {
             StoreList.ViewStoreList(false);
         }
     }
     else
     {
         Console.WriteLine("Store is empty!");
     }
 }
예제 #2
0
        public override void AddProduct()
        {
            if (StoreList.isEmpty())
            {
                Console.WriteLine("Store is empty!");
                return;
            }
            Console.WriteLine("Available products");
            StoreList.ViewStoreList(false);
            Console.WriteLine("Products in basket");
            Basket.ViewBasket();
            Console.Write("Enter product ID to add to basket: ");
            string tempID = Console.ReadLine();

            try
            {
                Product temp = StoreList.GetProduct(tempID).Clone();
                if (temp.ProductQuantity == 0)
                {
                    throw new NullReferenceException();
                }
                Console.Write("Enter quantity: ");
                double uquan = Convert.ToDouble(Console.ReadLine());
                if (uquan < 0)
                {
                    throw new FormatException();
                }
                if (temp.ProductQuantity - uquan >= 0)
                {
                    temp.ProductQuantity = uquan;
                    StoreList.GetProduct(tempID).ProductQuantity -= uquan;
                    Basket.Add(temp, uquan);
                    SaveUser();
                }
                else
                {
                    Console.WriteLine("Desired quantity is unavailable!");
                }
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("Product doesn\'t exist!");
            }
            catch (FormatException)
            {
                Console.WriteLine("Wrong value entered!");
            }
        }