Ejemplo n.º 1
0
        public void EditCarByID()
        {
            Console.Clear();
            if (_mapOfCars.Count == 0)
            {
                Console.WriteLine("List is empty add some cars first");
                Console.ReadLine();
            }
            else
            {
                WriteAllCars();
                int      id  = CheckID();
                CarModel car = carFactory.GetCarByID(id);
                try
                {
                    //
                    bool helpme = true;
                    while (helpme)
                    {
                        Console.WriteLine("What you want to edit (Enter Number)\n" +
                                          "1: Year of prodution\n" +
                                          "2: Number of Kilometers\n" +
                                          "3: Brand of the car\n" +
                                          "4: Type of the car \n" +
                                          "5: Place of sell \n" +
                                          "6: Price \n" +
                                          "7: Number of doors \n" +
                                          "8: Car Condition (Is still damaged?) \n" +
                                          "9: Fuel Type\n" +
                                          "0: Return");

                        int choice = CheckInt();
                        switch (choice)
                        {
                        case 1:
                        {
                            Console.WriteLine($"Old Year :{ _mapOfCars[id].ProductionYear}\n" +
                                              $"Enter new Year");
                            car.ProductionYear = CheckYear();
                            break;
                        }

                        case 2:
                        {
                            Console.WriteLine($"Old number of kilometers :{ _mapOfCars[id].DrivenKilometers}\n" +
                                              $"Enter new number of kilometers");
                            car.DrivenKilometers = CheckInt();
                            break;
                        }

                        case 3:
                        {
                            Console.WriteLine($"Old Brand of the car :{ _mapOfCars[id].Brand}\n" +
                                              $"Enter new Brand of the car");
                            car.Brand = CheckString();
                            break;
                        }

                        case 4:
                        {
                            Console.WriteLine($"Old Type of the car :{ _mapOfCars[id].TypeOfCar}\n" +
                                              $"Enter new Type of the car");
                            car.TypeOfCar = CheckString();
                            break;
                        }

                        case 5:
                        {
                            Console.WriteLine($"Old Place of sell :{ _mapOfCars[id].PlaceOfSell}\n" +
                                              $"Enter new Place of sell");
                            car.PlaceOfSell = CheckString();
                            break;
                        }

                        case 6:
                        {
                            Console.WriteLine($"Old Price :{ _mapOfCars[id].Price}\n" +
                                              $"Enter new Price");
                            car.Price = CheckDecimal();
                            break;
                        }

                        case 7:
                        {
                            Console.WriteLine($"Old Number of Doors :{ _mapOfCars[id].NumberOfDoors}\n" +
                                              $"Enter new Number of Doors");
                            car.NumberOfDoors = CheckInt();
                            break;
                        }

                        case 8:
                        {
                            Console.WriteLine($"Old Condition (Is car damaged?) :{ _mapOfCars[id].IsDamaged}\n" +
                                              $"What is new condition, Is car damaged? y/n");
                            car.IsDamaged = CheckBoolean();
                            break;
                        }

                        case 9:
                        {
                            Console.Write("Choose fuel type:");
                            foreach (var something in (Program.FuelTypes[])Enum.GetValues(typeof(Program.FuelTypes)))
                            {
                                Console.Write($" {something},");
                            }
                            Console.WriteLine();
                            car.Fuel = CheckFuel();
                            break;
                        }

                        case 0:
                        {
                            helpme = false;
                            break;
                        }

                        default:
                        {
                            Console.WriteLine("Wrong choice");
                            break;
                        }
                        }

                        if (helpme == true)
                        {
                            Console.WriteLine("Do you want to Edit something else on This car? y/n ");
                            if (!CheckBoolean())
                            {
                                helpme = false;
                            }
                        }
                    }
                    carFactory.RemoveCar(id);
                    carFactory.CreateCar(id, car.ProductionYear, car.DrivenKilometers, car.Brand, car.TypeOfCar, car.Price,
                                         car.PlaceOfSell, car.NumberOfDoors, car.IsDamaged, car.Fuel);
                    _mapOfCars = new Dictionary <int, CarModel>(carFactory.GetAllCars());
                }
                catch (KeyNotFoundException)
                {
                    Console.WriteLine("Error: Car List is empty" +
                                      "\nadd some Cars first");
                    Console.ReadLine();
                }
            }
        }