public static void ProductOperationMenu() { Console.WriteLine("Please Select Product Operation"); Console.WriteLine("a. Add a Product"); Console.WriteLine("b. List all Products"); Console.WriteLine("c. Search a Product"); Console.WriteLine("d. Delete a Product"); Console.WriteLine("e. Main Menu"); char ch1 = Convert.ToChar(Console.ReadLine()); switch (ch1) { case 'a': Console.WriteLine("Enter Product Name"); var ProductName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(ProductName) || int.TryParse(ProductName, out _)) { Console.WriteLine("Please Enter Only Char and It can not be Empty"); ProductName = Console.ReadLine(); } Console.WriteLine("Enter Short Code"); var shortCode = Console.ReadLine(); Console.WriteLine("Enter Description"); var desc = Console.ReadLine(); while (string.IsNullOrWhiteSpace(desc) || int.TryParse(desc, out _)) { Console.WriteLine("Please Enter Only Char and It can not be Empty"); desc = Console.ReadLine(); } Console.WriteLine("Enter Price"); int price = -1; bool flag = Int32.TryParse(Console.ReadLine(), out price); while (!flag || price <= 0) { Console.WriteLine("Please Enter Only Number and It can not be Empty/can not be negetive"); flag = Int32.TryParse(Console.ReadLine(), out price); } Console.WriteLine("Enter Manufacture Name"); var manufactureName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(manufactureName) || int.TryParse(manufactureName, out _)) { Console.WriteLine("Please Enter Only Char and It can not be Empty"); manufactureName = Console.ReadLine(); } Console.WriteLine("Enter Category Name"); var category = Console.ReadLine(); while (string.IsNullOrWhiteSpace(category) || int.TryParse(category, out _)) { Console.WriteLine("Please Enter Only Char and It can not be Empty"); category = Console.ReadLine(); } ProductOperation.AddProduct(ProductName, shortCode, desc, price, manufactureName, category); break; case 'b': ProductOperation.GetAllProduct(); break; case 'c': Console.WriteLine("Enter Product Name"); var SearchProductName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(SearchProductName) || int.TryParse(SearchProductName, out _)) { Console.WriteLine("Please Enter Only Char and It can not be Empty"); ProductName = Console.ReadLine(); } ProductOperation.SearchProduct(SearchProductName); break; case 'd': Console.WriteLine("Enter Product Name"); var DeleteProductName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(DeleteProductName) || int.TryParse(DeleteProductName, out _)) { Console.WriteLine("Please Enter Only Char and It can not be Empty"); DeleteProductName = Console.ReadLine(); } ProductOperation.DeleteProduct(DeleteProductName); break; case 'e': StartMenu.Menu(); break; default: Console.WriteLine("Invalid Selection!!"); ProductOperationMenu(); break; } }
public static void CategoryOperationMenu() { Console.WriteLine("***Welcome to ProductCatalog, Please Select Category Operation***"); Console.WriteLine("a. Enter a Category"); Console.WriteLine("b. List all Categories"); Console.WriteLine("c. Search a Category"); Console.WriteLine("d. Delete a Category"); Console.WriteLine("e. Main Menu"); char ch1 = Convert.ToChar(Console.ReadLine()); switch (ch1) { case 'a': Console.WriteLine("Enter Category Name"); var categoryName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(categoryName) || int.TryParse(categoryName, out _)) { Console.WriteLine("Please Enter Only Char and It can not be Empty"); categoryName = Console.ReadLine(); //break; } Console.WriteLine("Enter Short Code"); var shortCode = Console.ReadLine(); Console.WriteLine("Enter Description"); var desc = Console.ReadLine(); while (string.IsNullOrWhiteSpace(desc) || int.TryParse(desc, out _)) { Console.WriteLine("Please Enter Only Char and It can not be Empty"); desc = Console.ReadLine(); } CategoryOperation.AddCategory(categoryName, shortCode, desc); break; case 'b': CategoryOperation.GetAllCategory(); Console.ReadKey(); break; case 'c': Console.WriteLine("Enter Category Name"); var searchCategoryName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(searchCategoryName) || int.TryParse(searchCategoryName, out _)) { Console.WriteLine("Please Enter Only Char and It can not be Empty"); searchCategoryName = Console.ReadLine(); } CategoryOperation.SearchCategory(searchCategoryName); break; case 'd': Console.WriteLine("Enter Product Name"); var DeleteCategoryName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(DeleteCategoryName) || int.TryParse(DeleteCategoryName, out _)) { Console.WriteLine("Please Enter Only Char and It can not be Empty"); DeleteCategoryName = Console.ReadLine(); } CategoryOperation.DeleteCategory(DeleteCategoryName); break; case 'e': StartMenu.Menu(); break; default: Console.WriteLine("Invalid Selection!!"); CategoryOperationMenu(); break; } }