public void purchase() //Function to display shops for selection { localhost.WebService1 obj = new localhost.WebService1(); LaptopRead lap = new LaptopRead(); MouseRead mouse = new MouseRead(); PendriveRead pendrive = new PendriveRead(); int choice; Console.Clear(); Console.WriteLine("***************************** Welcome ******************************"); Console.WriteLine(); Console.WriteLine("------------Select the Shop 1/2/3 to display the Items--------------"); Console.WriteLine(); Console.WriteLine("-------> Shop-1: Laptop Shop-2: Mouse Shop-3: Pendrives <-------"); Console.WriteLine(); Console.Write("Choice: "); choice = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(); switch (choice) { case 1: dynamic x = obj.Getlaptop(); lap.lapDisplay(x); Console.ReadKey(); break; case 2: dynamic z = obj.Getmouse(); mouse.mouseDisplay(z); Console.ReadKey(); break; case 3: dynamic y = obj.Getpendrive(); pendrive.pendriveDisplay(y); Console.ReadKey(); break; default: Console.WriteLine("Invalid choice - Please enter 1/2/3"); Console.ReadLine(); Console.Clear(); break; } }
public void lapSelection(dynamic lapSelect) //fn to display laptop variant selected by the user { var user_id = Console.ReadLine(); int stock = 0; var flag = 0; String user_choice; Program pur = new Program(); LaptopRead lap = new LaptopRead(); foreach (var i in lapSelect) { if (user_id == i.Id.ToString()) { Console.WriteLine(); Console.WriteLine("---------------------------Your Selection-----------------------------"); Console.WriteLine(); String id = i.Id; String brandname = i.Brand; String price_detail = i.Price; String model_detail = i.Model; String Stock = i.Stock; lap.price = Convert.ToInt32(price_detail); stock = Convert.ToInt32(Stock); Program.brandCart.Add(brandname); Program.priceCart.Add(price_detail); Program.modelCart.Add(model_detail); Console.WriteLine("Id: {0}", id); Console.WriteLine("Brand: {0}", brandname); Console.WriteLine("Model: {0}", model_detail); Console.WriteLine("Price: Rs. {0}", price_detail); Console.WriteLine("----------------------------------------------------------------------"); flag = 1; } } if (flag == 1) { calculation(lapSelect); } else { Console.WriteLine("Please Enter Correct Item Id:"); lapSelection(lapSelect); } void calculation(dynamic calc) { do { Console.WriteLine(); Console.Write("Enter the Quantity Required:"); lap.qty = Convert.ToInt32(Console.ReadLine()); lap.localPrice = lap.qty * lap.price; Console.WriteLine("Total Price: Rs. {0}", lap.localPrice); Console.WriteLine(); Console.WriteLine("Do you want to Change quantity? (y/n)"); user_choice = Console.ReadLine(); Console.WriteLine(); while ((user_choice != "y") && (user_choice != "n")) { Console.WriteLine(); Console.WriteLine("Invalid Option. Please Choose 'y' or 'n'"); user_choice = Console.ReadLine(); } if (user_choice == "n") { stock = stock - lap.qty; foreach (var i in calc) { if (user_id == i.Id.ToString()) { i.Stock = stock; } } string output = JsonConvert.SerializeObject(calc, Formatting.Indented); File.WriteAllText(@"C:\Users\dhinesh.ks\Desktop\WebService\Laptop.json", output); selection(); } } while (user_choice == "y"); } void selection() { Program.quantity.Add(lap.qty); Program.totalPrice.Add(lap.localPrice); Program.purchasePrice += lap.localPrice; Program.laptopShopPrice += lap.localPrice; Console.WriteLine("Do you want to purchase another item...(Y/N)"); string choice = Console.ReadLine(); if (choice == "y" || choice == "Y") { pur.purchase(); } else if (choice == "N" || choice == "n") { pur.display(); } else { Console.WriteLine("Please Enter Y or N..."); selection(); } } }