public void buy()
        {
            Console.WriteLine("Buy an Item");
            Console.WriteLine("..............");
            Console.Write("Enter product id: ");
            int id = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter Quantity: ");
            int quantity = Convert.ToInt32(Console.ReadLine());

            product obj = productList.plist.First(x => x.id == id);

            if (obj != null)
            {
                if (obj.quantity == 0)
                {
                    Console.WriteLine("Opps.. Product out of stock!");
                }
                if (obj.quantity > 0 && (obj.quantity - quantity) >= 0)
                {
                    obj.quantity = obj.quantity - quantity;
                }
                else
                {
                    Console.WriteLine("");
                }
            }

            mainMenu o = new mainMenu();

            o.menu();
        }
        public void print()
        {
            Console.WriteLine("Id\tName\t\tAmount\t\tQuantity\tRating");
            Console.WriteLine("......................................................................");

            productList.printList();

            mainMenu ob = new mainMenu();

            ob.menu();
        }
 public void checkNinsert(int id, string name, int amount, int quantity, double rating)
 {
     if (id > 0)
     {
         bool check = productList.plist.Exists(x => x.id == id);
         if (check == true)
         {
             product obj = productList.plist.First(x => x.id == id);
             if (obj.name != name)
             {
                 Console.WriteLine("Produt Id & Name is not matched!!\nDo you want to update product name?");
                 Console.WriteLine("1. Update Product Name\n2. Add Product\n3. Main Menu");
                 Console.Write("Enter choice: ");
                 int aa = Convert.ToInt32(Console.ReadLine());
                 if (aa == 1)
                 {
                     obj.name     = name;
                     obj.quantity = obj.quantity + quantity;
                     obj.amount   = amount;
                     obj.rating   = rating;
                 }
                 else if (aa == 2)
                 {
                     addp();
                 }
                 else
                 {
                     mainMenu menu = new mainMenu();
                     menu.menu();
                 }
             }
             else
             {
                 obj.quantity = obj.quantity + quantity;
                 obj.amount   = amount;
                 obj.rating   = rating;
             }
         }
         else
         {
             productList.proAdd(id, name, amount, quantity, rating);
         }
     }
     else
     {
         Console.Clear();
         Console.WriteLine("Wrong input. Try again.");
         addp();
     }
 }
Ejemplo n.º 4
0
        public void delete()
        {
            Console.Write("\nEnter Id to delete a product: ");
            int  x = Convert.ToInt32(Console.ReadLine());
            bool a = productList.plist.Exists(z => z.id == x);

            if (a == true)
            {
                productList.plist.RemoveAll(p => p.id == x);
            }
            else
            {
                Console.WriteLine("\nProduct not found to be deleted.\n");
            }


            mainMenu ob = new mainMenu();

            ob.menu();
        }
        public void find()
        {
            Console.Write("Enter Prodct ID: ");
            int x = Convert.ToInt32(Console.ReadLine());

            bool a = productList.plist.Exists(z => z.id == x);

            if (a == true)
            {
                product obj = productList.plist.First(xx => xx.id == x);

                Console.WriteLine("\n\nId\tName\t\tAmount\t\tQuantity\tRating");
                Console.WriteLine(".....................................................................");
                Console.WriteLine($"{obj.id}\t{obj.name}\t\t{obj.amount}\t\t{obj.quantity}\t\t{obj.rating}");
            }
            else
            {
                Console.WriteLine("Produc Not Found!!");
            }
            mainMenu ob = new mainMenu();

            ob.menu();
        }
        public void show()
        {
            if (productList.plist.Count > 1)
            {
                int max = productList.plist.Max(x => x.quantity);
                //Console.WriteLine(max);
                int min = productList.plist.Min(x => x.quantity);
                //Console.WriteLine(min);

                product obj  = productList.plist.First(x => x.quantity == max);
                product obj1 = productList.plist.First(y => y.quantity == min);


                Console.WriteLine($"Maximum Quantity Product: {obj.name}");
                Console.WriteLine($"Minimum Quantity Product: {obj1.name}");

                Console.WriteLine("Id\tName\t\tAmount\t\tQuantity\tRating");
                Console.WriteLine(".............................................................................");

                Console.WriteLine($"{obj.id}\t{obj.name}\t\t{obj.amount}\t\t{obj.quantity}\t\t{obj.rating}");
                Console.WriteLine($"{obj1.id}\t{obj1.name}\t\t{obj1.amount}\t\t{obj1.quantity}\t\t{obj1.rating}");
            }
            else if (productList.plist.Count == 1)
            {
                Console.WriteLine("\nOnly one product found.\n");
                printAll print = new printAll();
                print.print();
            }
            else
            {
                Console.WriteLine("\nProduct list is empty!! \n\n");
            }

            mainMenu ob = new mainMenu();

            ob.menu();
        }
        public void addp()
        {
            Console.Clear();
            checkNinsert(1, "mouse", 300, 50, 8.1);
            checkNinsert(2, "kboard", 600, 10, 8.3);
            checkNinsert(3, "monitor", 6000, 25, 7.3);
            checkNinsert(4, "HDD", 3500, 15, 8.4);
            checkNinsert(5, "RAM", 4000, 50, 9.3);

            //takeinput();

            Console.Write("Product added successfully.\n\nEnter 1 to add more product\n\nEnter 2 for Main menu.\n\nEnter: ");
            int a = Convert.ToInt32(Console.ReadLine());

            if (a == 1)
            {
                addp();
            }
            else
            {
                mainMenu ob = new mainMenu();
                ob.menu();
            }
        }
        public static void Main(string[] args)
        {
            mainMenu obj = new mainMenu();

            obj.menu();
        }