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 RentApartment() { Console.WriteLine("Available apartments for rent: "); foreach (var apartment in ApartmentsForRent) { apartment.Print(); } Console.WriteLine("Choose by typing the id of the apartment! "); int apartmentID = 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 tempApartment = new Apartment(); foreach (var apartment1 in ApartmentsForRent) { if (apartment1.ID == apartmentID) { tempApartment = apartment1; } } var apartmentRent = new ApartmentRent { ID = apartmentID, LesseeName = name, NumberOfDays = days, PricePerDay = 20.0, Apartment = tempApartment, EntryDate = DateTime.Now }; ApartmentRents.Add(apartmentRent); ApartmentsForRent.Remove(tempApartment); }