public void Save(TestDriveCarViewModel testdrive) { var car = ListCarTest.FirstOrDefault(o => o.Car.ID == testdrive.ID); if (car == null) { return; } var tst = car.TestDrives.FirstOrDefault(o => o.Equals(testdrive)); testdrive.IsChanged = false; if (tst == null) { car.TestDrives.Add(testdrive); } else { tst.Update(testdrive.Model); } _handler.Save(testdrive.Model); }
private void AddCarTests() { foreach (var car in _handler.Cars) { var el = ListCarTest.FirstOrDefault(o => o.Car != null && o.Car.CarNumber == car.CarModel.DID); var added = el == null; if (added) { el = new CarTestDrivesViewModel(new TestDriveCarViewModel(car.CarModel, ListCarTest.Count)); } foreach (var test in _handler.TestDrives.Where(o => o.Car.CarNumber == el.Car.CarNumber)) { el.Update(test); } if (added) { ListCarTest.Add(el); } else { el.Update(car.CarModel); } } }