Example #1
0
        /// <summary>
        /// Containing switch to handle which method to execute
        /// </summary>
        /// <param name="option">Option to Add\Delete\Update Car Information</param>
        public static void MainCall(int option)
        {
            int result = 0;
            int carID1 = 0;

            string        currentDirectory = Directory.GetCurrentDirectory();
            DirectoryInfo directory        = new DirectoryInfo(currentDirectory);
            var           fileName         = Path.Combine(directory.FullName, "CarSimple.csv");
            CarData       carRespo         = new CarData(fileName);
            var           fileContents     = carRespo.ReadCarStats();

            switch (option)
            {
            case 1:

                AddCar(fileContents, carRespo);
                break;

            case 2:

                View(fileContents, carRespo);
                Console.ReadKey();
                int option1 = DisplayMenu();
                MainCall(option1);
                break;

            case 3:
                Console.Clear();
                Console.WriteLine("  \t ___________________________________");
                Console.WriteLine("  \t|                                    |");
                Console.WriteLine("  \t|   Welcome To Edit Car Application  |");
                Console.WriteLine("  \t|____________________________________|\n");
                Console.Write("\n\tEnter a Car ID # which you wish to Update: ");
                carID1 = Convert.ToInt32(Console.ReadLine());
                result = Edit(carID1, fileContents, carRespo);
                break;

            case 4:

                Console.Clear();
                Console.WriteLine("  \t ______________________________________");
                Console.WriteLine("  \t|                                      |");
                Console.WriteLine("  \t|   Welcome To Delete Car Application  |");
                Console.WriteLine("  \t|______________________________________|\n");
                Console.Write("\n\tEnter a Car ID # which you wish to Delete: ");
                carID1 = Convert.ToInt32(Console.ReadLine());
                result = Delete(carID1, fileContents, carRespo);
                if (result == 1)
                {
                    Console.WriteLine("\n\n\tCar with ID # " + carID1 + " has been deleted!!!!!\n");
                    Console.WriteLine("\n\n-------------------End of Delete Car Application----------------------\n");
                    Console.Write("\n\n\t\tPress Any Key to Return to Menu");
                    Console.ReadKey();
                    option1 = DisplayMenu();
                    MainCall(option1);
                }
                else
                {
                    Console.WriteLine("\n\n\tCar with ID # " + carID1 + " does not Exist!!!\n\n");
                    Console.WriteLine("\n\n-------------------End of Delete Car Application----------------------\n");
                    Console.Write("\n\n\t\tPress Any Key to Return to Menu");
                    Console.ReadKey();
                    option1 = DisplayMenu();
                    MainCall(option1);
                }

                break;

            case 5:
                readscv();
                Console.WriteLine("\n\n-------------------End of Car DataSet File----------------------\n");
                Console.Write("\n\n\t\tPress Any Key to Return to Menu");
                Console.ReadKey();
                option1 = DisplayMenu();
                MainCall(option1);
                break;

            case 6:
                Console.WriteLine("\n\t----------BYEEEEEEEEEEEEEEEEEEEEE!-----------");
                break;

            default:
                Console.WriteLine("\n\n----------Invalid Input!!!!!!Re-Enter the Input Value!!!----------\n");
                option1 = DisplayMenu();
                MainCall(option1);
                break;
            }
        }