Exemplo n.º 1
0
        private bool RemoveProduct()
        {
            if (Basket.isEmpty())
            {
                Console.WriteLine("Basktet is empty, functionality disabled!");
                return(false);
            }
            Console.Write("Enter id of product to remove/remove from: ");
            string id = Console.ReadLine();

            if (Basket.GetProduct(id) == null)//check if product exists in basket
            {
                Console.WriteLine("Item entered is not in basket!");
                Console.Write("Press any key to continue...");
                Console.ReadKey();
                return(false);
            }
            try
            {
                Console.Write("Enter quantity to remove: ");
                double quan = Convert.ToDouble(Console.ReadLine());
                if (quan < 0)
                {
                    throw new FormatException();
                }
                if (quan != 0)//dont delete if quantity is 0
                {
                    if (Basket.DeleteProduct(id, quan))
                    {
                        StoreList.AddProduct(id, quan);
                        SaveUser();
                        if (Basket.isEmpty())
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("Wrong value entered!");
                Console.Write("Press any key to continue...");
                Console.ReadKey();
            }
            return(true);
        }
Exemplo n.º 2
0
        public override void AddProduct()
        {
            string id;

            Console.Write("Please enter product ID: ");
            id = Console.ReadLine();
            if (StoreList.GetProduct(id) != null)
            {
                Console.Write("Product already exists, would you like to add by a certain quantity?(Y/N): ");
                string uchoice = Console.ReadLine().ToUpper();
                try
                {
                    if (uchoice == "Y")
                    {
                        while (true)
                        {
                            Console.Write("Enter quantity to increase by: ");
                            double quan = Convert.ToDouble(Console.ReadLine());
                            if (quan < 0)
                            {
                                throw new FormatException();
                            }
                            StoreList.AddProduct(id, quan);
                            break;
                        }
                    }
                    else if (uchoice != "N")
                    {
                        throw new FormatException();
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Wrong value entered!");
                }
            }
            else
            {
                StoreList.AddProduct(id);
            }
        }