Ejemplo n.º 1
0
        public void UpdateExistingContent()
        {
            Console.Clear();
            Console.WriteLine("Enter the name of the person's data you'd like to update.");
            string firstName = Console.ReadLine();
            object hybridCar = null;
            GreenPlanContent_Repo oldItem = _repo.FindCarByName(hybridCar);

            if (oldItem == null)
            {
                Console.WriteLine("Person not found, press any key to continue...");
                Console.ReadKey();
                return;
            }
            GreenPlanContent_Repo newItem = new GreenPlanContent_Repo();

            oldItem.HybridCar
            oldItem.ElectricCar;
            Console.WriteLine("Which property would you like to update:\n" +
                              "1. Hybrid Car\n" +
                              "2. Electric Car\n" +
                              "6. Nevermind");
            string selection = Console.ReadLine();

            switch (selection)
            {
            case "1":
                Console.WriteLine("Enter a new title");
                string newFirstName = Console.ReadLine();
                newItem.HybridCar = new hybridCar;
                bool wasSuccessful = _repo.UpdateExistingContent(hybridCar, newCar);
                if (wasSuccessful)
                {
                    Console.WriteLine("Name successfully updated");
                }
                else
                {
                    Console.WriteLine($"Error: Could not update {hybridCar}");
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        public void UpdateExistingContent()
        {
            Console.Clear();
            Console.WriteLine("Enter the name of the vehicles's data you'd like to update.");
            string           cartype = Console.ReadLine();
            GreenPlanContent oldItem = _repo.FindCarByName(cartype);

            if (oldItem == null)
            {
                Console.WriteLine("vehicle not found, press any key to continue...");
                Console.ReadKey();
                return;
            }
            GreenPlanContent newItem = new GreenPlanContent(
                oldItem.CarType,
                oldItem.PriceEstimate,
                oldItem.FuelCost,
                oldItem.Mileage,
                oldItem.CarName

                );

            Console.WriteLine("Which property would you like to update:\n" +
                              "1. CarType\n" +
                              "2. CarName\n" +
                              "3. Price Estimate\n" +
                              "4. Fuel Cost\n" +
                              "5. Mileage\n" +
                              "6. Nevermind");
            string selection = Console.ReadLine();

            switch (selection)
            {
            case "1":
                Console.WriteLine("Enter a car type.\n" +
                                  "Gas\n" +
                                  "Hybrid\n" +
                                  "Electric");
                string newFirstName = Console.ReadLine();
                newItem.CarType = newFirstName;
                bool wasSuccessful = _repo.UpdateExistingContent(cartype, newItem);
                if (wasSuccessful)
                {
                    Console.WriteLine("Car Type successfully updated");
                }
                else
                {
                    Console.WriteLine($"Error: Could not update {cartype}");
                }
                break;

            default:
                break;

            case "2":
                Console.WriteLine("Enter a new car name");
                string newCarName = Console.ReadLine();
                newItem.CarName = newCarName;
                break;

            case "3":
                Console.WriteLine("Enter price estimate");
                string priceEstimateAsString = Console.ReadLine();
                double priceEstimateAsDouble = double.Parse(priceEstimateAsString);
                newItem.PriceEstimate = priceEstimateAsDouble;
                break;

            case "4":
                Console.WriteLine("Enter Vechile fuel cost");
                string fuelCostAsString = Console.ReadLine();
                double fuelCostAsDouble = double.Parse(fuelCostAsString);
                newItem.FuelCost = fuelCostAsDouble;
                break;
            }
        }