public static void MakePurchase(SuperDume s, Client c) { bool canAdd = true; int optionMakePurchase = -1, nItems = 0; float pTotal = 0; Product productCode; List <Product> cart = new List <Product>(); do { Console.WriteLine("--------------------------"); Console.WriteLine("1 - Add Product to Shopping Cart"); Console.WriteLine("2 - Shopping Cart"); Console.WriteLine("3 - List Products"); Console.WriteLine("4 - End purchase"); if (cart.Count() == 0) { Console.WriteLine("0 - Back"); } Console.WriteLine("--------------------------"); Console.WriteLine("Input option:"); optionMakePurchase = int.Parse(Console.ReadLine()); switch (optionMakePurchase) { case 1: { canAdd = true; Console.WriteLine("Select Product: "); productCode = CheckProductExists(s, int.Parse(Console.ReadLine())); if (productCode == null) { Utils.PrintError("Product does not exist."); } else { if (productCode.Quantity >= 1) { foreach (Product p in cart) { if (productCode.Code == p.Code) { p.Quantity += 1; canAdd = false; } } if (canAdd == true) { cart.Add(new Product(productCode.Code, productCode.Description, productCode.Price, 1)); } pTotal += productCode.Price; nItems += 1; productCode.Quantity -= 1; } else { Utils.PrintError("Out of stock."); } } } break; case 2: s.ListShoppingCart(cart); break; case 3: s.ListProducts(); break; case 4: { if (nItems > 0) { s.MakePurchase(c, cart, "", nItems, pTotal); optionMakePurchase = 0; } else { Utils.PrintError("Shopping Cart is empty."); } } break; } } while (optionMakePurchase != 0); }
static void Main(string[] args) { Console.ForegroundColor = System.ConsoleColor.Green; SuperDume superdume = new SuperDume(); int option = -1; int optionStockManager = -1; do { Console.WriteLine("-------:.SuPeRDuMe.:------"); Console.WriteLine("1 - Stock Manager"); Console.WriteLine("2 - Client Manager"); Console.WriteLine("3 - Save Data"); Console.WriteLine("4 - Load Data"); Console.WriteLine("0 - Exit"); Console.WriteLine("--------------------------"); Console.WriteLine("Input option:"); option = int.Parse(Console.ReadLine()); switch (option) { case 1: { // stock manager do { Console.WriteLine("--------------------------"); Console.WriteLine("1 - List Products"); Console.WriteLine("2 - Add New Product"); Console.WriteLine("3 - Update Stock"); Console.WriteLine("4 - Delete Product"); Console.WriteLine("0 - Back"); Console.WriteLine("--------------------------"); optionStockManager = int.Parse(Console.ReadLine()); switch (optionStockManager) { case 1: // list products superdume.ListProducts(); break; case 2: // add new product AddProduct(superdume); break; case 3: // update stock UpdateStock(superdume); break; case 4: { // delete product Product p; Console.WriteLine("Select Product: "); p = CheckProductExists(superdume, int.Parse(Console.ReadLine())); if (p == null) { Utils.PrintError("Wrong code/Product does not exist"); } else { superdume.DeleteProduct(p); } break; } } } while (optionStockManager != 0); break; } case 2: { ClientManagerMenu(superdume); break; } case 3: { WriteBinFile(superdume, Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\superdume.bin"); break; } case 4: { superdume = ReadBinFile(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\superdume.bin"); if (superdume == null) { Utils.PrintError("There is no saved data."); superdume = new SuperDume(); /* Easter Egg * * Adding some default clients and products */ Utils.PrintEaster("You found our Easter Egg! Check clients and products."); superdume.AddClient("Francisco Santos", "Braga", "915874156", "*****@*****.**", "001", "001"); superdume.AddClient("Pedro Fernandes", "Algures", "961813492", "*****@*****.**", "002", "002"); superdume.AddClient("Jorge Noro", "Viana", "935814921", "*****@*****.**", "003", "003"); superdume.AddProduct(123, "Potatoes", 0.99f, 250); superdume.AddProduct(124, "Ham", 1.99f, 100); superdume.AddProduct(125, "Cheese", 5.41f, 100); superdume.AddProduct(126, "Gold", 100.0f, 5); superdume.AddProduct(127, "Easter Egg", 500.0f, 1); } break; } case 0: break; } ; } while (option != 0); }