private void LoadShooters(int personId) { Shooter[] shooters = _shooterDataStore.FindByPersonId(personId).ToArray(); Shooters = new ObservableCollection <ShooterViewModel>( shooters.Select(shooter => { ShooterViewModel vm = new ShooterViewModel(); vm.Initialize(shooter); return(vm); })); SelectedShooter = Shooters.FirstOrDefault(); }
public void Initialize() { _personDataStore = ServiceLocator.Current.GetInstance <IPersonDataStore>(); _shooterDataStore = ServiceLocator.Current.GetInstance <IShooterDataStore>(); _shooterNumberService = ServiceLocator.Current.GetInstance <IShooterNumberService>(); _shooterDataWriter = ServiceLocator.Current.GetInstance <ISsvShooterDataWriterService>(); _collectionShooterDataStore = ServiceLocator.Current.GetInstance <ICollectionShooterDataStore>(); _shooterCollectionDataStore = ServiceLocator.Current.GetInstance <IShooterCollectionDataStore>(); _serviceDeskConfiguration = ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>(); MessengerInstance.Register <PersonSelectedMessage>(this, x => { UpdateCommandCanExecuteOnSelectedPersonChanged(); LoadShooters(x.PersonId); }); MessengerInstance.Register <SetSelectedPersonMessage>(this, x => { SelectedPerson = FilteredPersons.FirstOrDefault(person => person.PersonId == x.PersonId); }); MessengerInstance.Register <SetSelectedShooterMessage>(this, x => { SelectedShooter = Shooters.FirstOrDefault(s => s.Shooter.ShooterId == x.ShooterId); if (SelectedShooter == null) { SelectedShooter = Shooters.FirstOrDefault(); } }); MessengerInstance.Register <RefreshDataFromRepositoriesMessage>(this, x => { UiPerson selectedPerson = SelectedPerson; ShooterViewModel selectedShooter = SelectedShooter; LoadPersons(); if (selectedPerson != null) { MessengerInstance.Send(new SetSelectedPersonMessage(selectedPerson.PersonId)); } if (selectedShooter != null) { MessengerInstance.Send(new SetSelectedShooterMessage(selectedShooter.Shooter.ShooterId)); } }); }
private void LoadShooters(int personId) { Shooter[] shooters = _shooterDataStore.FindByPersonId(personId).ToArray(); Shooters = new ObservableCollection<ShooterViewModel>( shooters.Select(shooter => { ShooterViewModel vm = new ShooterViewModel(); vm.Initialize(shooter); return vm; })); SelectedShooter = Shooters.FirstOrDefault(); }