private void LoadShooterList() { try { int selectedShooterId = default(int); if (SelectedUiShooter != null) { selectedShooterId = SelectedUiShooter.ShooterId; } Func <Shooter, UiShooter> selector = shooter => new UiShooter { PersonId = shooter.PersonId, ShooterNumber = shooter.ShooterNumber, ShooterId = shooter.ShooterId }; List <UiShooter> shooterListItems; if (SelectedUiPerson != null) { shooterListItems = _shooterDataStore.FindByPersonId(SelectedUiPerson.PersonId).Select(selector).ToList(); } else { shooterListItems = _shooterDataStore.GetAll().Select(selector).ToList(); } ShooterListItems = new ObservableCollection <UiShooter>(shooterListItems.Select(_ => _.FetchPerson(_personDataStore))); SelectedUiShooter = ShooterListItems.SingleOrDefault(_ => _.ShooterId == selectedShooterId); } catch (Exception e) { ReportException(e); } }
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(); }