public MainViewModel(DatabaseService databaseService) { _databaseService = databaseService; _databaseService.CarUpdated += OnDatabaseServiceCarUpdated; Cars = new ObservableCollection <CarViewModel>(); CurrentCar = new CarViewModel(new Car() { Color = "Цвет", Model = "Модель" }); }
private void OnDatabaseServiceCarUpdated(DatabaseService sender, DatabaseServiceUpdateEventArgs <Car> args) { _logger.Trace($"{nameof(OnDatabaseServiceCarUpdated)}. {nameof(args.UpdateInfo)} = {args.UpdateInfo.ToString()}"); switch (args.UpdateInfo) { case DatabaseServiceUpdate.Added: foreach (var car in args.Data) { var viewModel = new CarViewModel(car); Cars.Add(viewModel); _logger.Debug($"{nameof(Add)}. Car added: {viewModel.Model}, {viewModel.Model}."); } break; case DatabaseServiceUpdate.Deleted: // Cars.Remove(...) break; default: throw new ArgumentOutOfRangeException(nameof(args) + "." + nameof(args.UpdateInfo)); } }