// Get the cars from the Model public void GetCars() { carManager = new CarManager(); _SelectedIndex = -1; _Cars.Clear(); foreach (var car in carManager.Cars) { var newCar = new CarViewModel(car); newCar.PropertyChanged += Car_OnNotifyPropertyChanged; // Subscribe object to the OnNotifyPropertyChanged Event _Cars.Add(newCar); } }
// Delete Car from list public bool Delete(CarViewModel carToDelete) { bool success = false; Debug.WriteLine("CMVM: Delete Car - Starting attempt"); try { this.carManager.Delete(carToDelete); this._Cars.Remove(carToDelete); this._SelectedIndex = -1; Debug.WriteLine("CMVM: Delete Car - Successful"); success = true; } catch (Exception ex) { Debug.WriteLine("CMVM: Delete Car - Failed"); Debug.WriteLine("Error: " + ex); } return(success); }
public CarViewModel GetCarById(int carId) { CarViewModel car = this._Cars.Where((x) => x.CarId == carId).FirstOrDefault(); return(car); }