public void ViewRentByID() { Console.Write("Rent ID: "); int id = int.Parse(Console.ReadLine()); var carRent = new CarRent(); var apartmentRent = new ApartmentRent(); foreach (var car in CarRents) { if (car.ID == id) { carRent = car; } } foreach (var apartment in ApartmentRents) { if (apartment.ID == id) { apartmentRent = apartment; } } if (carRent != null) { carRent.Print(); } else if (apartmentRent != null) { apartmentRent.Print(); } else { Console.WriteLine("Rent with this ID does not exist!"); } }
private void RentCar() { Console.WriteLine("Available cars for rent: "); foreach (var car in CarsForRent) { car.Print(); } Console.WriteLine("Choose by typing the id of the car! "); int carID = int.Parse(Console.ReadLine()); Console.WriteLine("Write you name:"); string name = Console.ReadLine(); Console.WriteLine("NumberO of Days:"); int days = int.Parse(Console.ReadLine()); var tempCar = new Car(); foreach (var car1 in CarsForRent) { if (car1.ID == carID) { tempCar = car1; } } var carRent = new CarRent { ID = carID, LesseeName = name, NumberOfDays = days, PricePerDay = 20.0, Car = tempCar, EntryDate = DateTime.Now }; CarRents.Add(carRent); CarsForRent.Remove(tempCar); }