public CarRecord TryGetCarByEcv(string ecv) { CarRecord car; return(CarsByEcv.TryGetEqual(new CarRecord { Ecv = ecv }, out car) ? car : null); }
// public bool TryDeleteCarByVin(string vin) { VinEcvRecord vinEcv; if (EcvsByVin.TryRemove(new VinEcvRecord { Vin = vin }, out vinEcv)) { var r = new CarRecord(); r.Ecv = vinEcv.Ecv; bool removed = CarsByEcv.TryRemove(r); Debug.Assert(removed); return(true); } return(false); }
public bool TryDeleteCarByEcv(string ecv) { CarRecord car; if (CarsByEcv.TryRemove(new CarRecord { Ecv = ecv }, out car)) { bool removed = EcvsByVin.TryRemove(new VinEcvRecord { Vin = car.Vin }); Debug.Assert(removed); return(true); } return(false); }
public void Dispose() { CarsByEcv.Dispose(); EcvsByVin.Dispose(); Drivers.Dispose(); }
// Returns true if added new car. public bool AddOrUpdateCar(CarRecord selectedCar) { bool carExists = false; var existingCarVin = TryGetCarByEcv(selectedCar.Ecv)?.Vin; VinEcvRecord vinEcv = null; if (existingCarVin != null) { //selectedCar.Vin = existingCarVin; //existingCarVin = selectedCar.Vin; carExists = true; } else { if (EcvsByVin.TryGetEqual(new VinEcvRecord { Vin = selectedCar.Vin }, out vinEcv)) { //selectedCar.Ecv = vinEcv.Ecv; carExists = true; } } // ak menim klucove atributy if (carExists) { if (existingCarVin != null && !selectedCar.Vin.Equals(existingCarVin)) { // ak menim vin a najdem auto podla ecv TryDeleteCarByEcv(selectedCar.Ecv); // zmazem auto podla ecv // pridam nove auto carExists = false; } else if (vinEcv != null && !selectedCar.Ecv.Equals(vinEcv.Ecv)) { // ak menim ecv a najdem auto podla vin TryDeleteCarByVin(selectedCar.Vin); // zmazem auto podla vin // pridam nove auto carExists = false; } } if (!carExists) { bool addedVinEcv = EcvsByVin.Add(new VinEcvRecord { Vin = selectedCar.Vin, Ecv = selectedCar.Ecv }, updateIfExists: false); //Console.WriteLine("Nenaslo take auto"); Debug.Assert(addedVinEcv); } bool added = CarsByEcv.Add(selectedCar, updateIfExists: true); Debug.Assert(added == !carExists); //Console.WriteLine("Pridane do ECV-VIN tabulky"); return(added); }