public bool AddVehicle(MyVehicle vehicle, bool saveToDisk = false) { if (_vehicles.Contains(vehicle) || _vehicles.Any(v => vehicle.SameAs(v))) { return(false); } _vehicles.Add(vehicle); if (saveToDisk) { SaveVehicle(vehicle); } return(true); }
public bool UpdateVehicle(MyVehicle vehicle, bool saveToDisk = false) { var vehicleIndex = _vehicles.FindIndex(v => vehicle.SameAs(v)); if (vehicleIndex == -1) { return(false); } _vehicles[vehicleIndex] = vehicle; // If object instance is the same, there is obviously nothing to update, but does no harm either. if (saveToDisk) { SaveVehicle(vehicle); } return(true); }