Пример #1
0
        public void RunApp()
        {
            inventoryHandler.CreateDBAndTables();
            string choice;

            do
            {
                choice = DisplayMenuAndGetInChoice();

                switch (choice)
                {
                case "1":
                    inventoryHandler.DisplayTable <ProductCategoryModel>(inventoryHandler.LoadModel <ProductCategoryModel>(productCategory));
                    break;

                case "2":
                    inventoryHandler.DisplayTable <ProductModel>(inventoryHandler.LoadModel <ProductModel>(product));
                    break;

                case "3":
                    (ProductCategoryModel, bool)ValidatedProductCategory = inventoryHandler.CreateModel <ProductCategoryModel>();
                    SaveOnlyIfValidModel((InventoryHandler)inventoryHandler, ValidatedProductCategory);
                    break;

                case "4":
                    ///For console UI extra validation is needed because user can enter anything which might not be in database
                    ///In WPF a combobox can only contains values which is loaded from database.
                    (ProductModel, bool)ValidatedProduct = inventoryHandler.CreateModel <ProductModel>();

                    SaveOnlyIfValidModel((InventoryHandler)inventoryHandler, ValidatedProduct);
                    break;

                case "5":
                    DeleteDataBase((InventoryHandler)inventoryHandler, "Are you sure to delete all data? (y/n)");
                    break;

                case "6":
                    Console.WriteLine("Thanks for using this application");
                    break;

                default:
                    Console.WriteLine("That was an invalid choice. Hit enter and try again.");
                    break;
                }
                Console.WriteLine("Hit return to continue...");
                Console.ReadLine();
            } while (choice != "6");
        }