예제 #1
0
        private void CreateNewCar()
        {
            Console.Clear();

            CarComparison newCar = new CarComparison();

            Console.WriteLine("Enter the type of car:\n" +
                              "1. Electric\n" +
                              "2. Gas\n" +
                              "3. Hybrid");
            string typesAsString = Console.ReadLine();
            int    typesAsInt    = int.Parse(typesAsString);

            newCar.Types = (CarType)typesAsInt;
            Console.WriteLine(newCar.Types);

            Console.WriteLine("Enter the make:");
            newCar.SetMake(Console.ReadLine());

            Console.WriteLine("Enter the model:");
            newCar.SetModel(Console.ReadLine());

            Console.WriteLine("Enter the safety rating:");
            string rating = Console.ReadLine();

            newCar.SafetyRating = double.Parse(rating);

            Console.WriteLine("Enter the average annual emissions (metric tons):");
            string emissions = Console.ReadLine();

            newCar.Emissions = double.Parse(emissions);

            _carRepo.AddNewCar(newCar);
        }
예제 #2
0
        private void UpdateExistingCar()
        {
            Console.Clear();

            ViewAllCars();

            Console.WriteLine("Which car would you like to update?");

            string oldCar = Console.ReadLine();

            CarComparison newCar = new CarComparison();

            Console.WriteLine("Enter the type of car:\n" +
                              "1. Electric\n" +
                              "2. Gas\n" +
                              "3. Hybrid");
            string typesAsString = Console.ReadLine();
            int    typesAsInt    = int.Parse(typesAsString);

            newCar.Types = (CarType)typesAsInt;
            Console.WriteLine(newCar.Types);

            Console.WriteLine("Enter the make:");
            newCar.SetMake(Console.ReadLine());

            Console.WriteLine("Enter the model:");
            newCar.SetModel(Console.ReadLine());

            Console.WriteLine("Enter the safety rating:");
            string rating = Console.ReadLine();

            newCar.SafetyRating = double.Parse(rating);

            Console.WriteLine("Enter the average annual emissions (metric tons):");
            string emissions = Console.ReadLine();

            newCar.Emissions = double.Parse(emissions);

            bool wasUpdated = _carRepo.UpdateExistingCar(oldCar, newCar);

            if (wasUpdated)
            {
                Console.WriteLine("Successful Update!");
            }
            else
            {
                Console.WriteLine("Date was not updated. Please try again.");
            }
        }