public bool RentVehicle(string vehicleType, DateTime startDateTime, int hours) { double minCost = 0; VehicleBooking vehicleBooking = null; FlipKarBranch bookingbranch = null; foreach (var branch in Branches) { var booking = branch.Value.RentVehicle(vehicleType, startDateTime, hours); if (minCost > booking?.TotalCost) { vehicleBooking = booking; minCost = booking.TotalCost; bookingbranch = branch.Value; } } if (bookingbranch != null) { bookingbranch.AddBooking(vehicleBooking); return(true); } Console.WriteLine("No Vehicle"); return(false); }
public void AddBooking(VehicleBooking vehicleBooking) { if (VehicleBookings.ContainsKey(vehicleBooking.Vehicle)) { VehicleBookings[vehicleBooking.Vehicle].Add(vehicleBooking); } else { List <VehicleBooking> bookings = new List <VehicleBooking>(); bookings.Add(vehicleBooking); VehicleBookings.Add(vehicleBooking.Vehicle, bookings); } }