private void ExecuteSearchShooterCommand(string obj) { int shooterNumber; if (int.TryParse(obj, out shooterNumber)) { Shooter shooter = _shooterDatastore.FindByShooterNumber(shooterNumber); if (shooter != null) { if (shooter.PersonId != null) { UiShooter uiShooter = UiBusinessObjectMapper.ToUiShooter(shooter).FetchPerson(_personDatastore.FindById((int)shooter.PersonId)); CurrentShooterLabel = string.Format("{0} {1} ({2})", uiShooter.LastName, uiShooter.FirstName, uiShooter.ShooterNumber); } int shooterId = shooter.ShooterId; List <UiSession> session = _sessionDatastore.FindByShooterId(shooterId).Select(UiBusinessObjectMapper.ToUiSession).ToList(); session.ForEach(_ => { if (_.ProgramItemId != null) { _.ProgramDescription = string.Format("{0}", _programItemDatastore.FindById((int)_.ProgramItemId).ProgramName); } }); UiSessions = new ObservableCollection <UiSession>(session); SelectedUiSession = UiSessions.FirstOrDefault(); } } }
private void SelectedPersonChanged() { if (MessengerInstance == null) { return; } if (SelectedPerson != null) { Dictionary <int, List <int> > sessionToSubsession = (from session in _sessionDataStore.FindByShooterId(SelectedPerson.ShooterId) join subsession in _sessionSubtotalDataStore.GetAll() on session.SessionId equals subsession.SessionId orderby session.ProgramNumber group subsession by session.SessionId).ToDictionary(_ => _.Key, _ => _.Select(fo => fo.SessionSubtotalId).ToList()); Sessions = new ObservableCollection <SessionViewModel>(); foreach (KeyValuePair <int, List <int> > keyValuePair in sessionToSubsession) { Session session = _sessionDataStore.FindById(keyValuePair.Key); { ParticipationDescription participation = _sdk.ParticipationDescriptions.GetAll() .SingleOrDefault(x => x.ProgramNumber == session.ProgramNumber.ToString()); string programName = participation == null ? "unknown" : participation.ProgramName; SessionViewModel svm = new SessionViewModel { LaneNumber = session.LaneNumber, ProgramName = string.Format("{0} [{1}]", programName, session.ProgramNumber), SessionId = session.SessionId, ShooterIsParticipating = _shooterParticipationDataStore.FindByShooterId(SelectedPerson.ShooterId).Any(x => x.ProgramNumber == session.ProgramNumber) }; List <Shot> shots = new List <Shot>(); foreach (int subsessionId in keyValuePair.Value) { shots.AddRange(_shotDataStore.FindBySubSessionId(subsessionId).OrderBy(shot => shot.Ordinal)); } svm.Shots = new ObservableCollection <Shot>(shots); svm.Total = shots.Sum(s => s.PrimaryScore); Sessions.Add(svm); } } } else { Sessions = new ObservableCollection <SessionViewModel>(); } }