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>(); } }
private void ShootingRangeOnBestShot(object sender, ShotEventArgs e) { if (_sessionsOngoing.ContainsKey(e.LaneNumber)) { SubSession currentSubSession = _sessionsOngoing[e.LaneNumber].CurrentSubsession(); Shot shot = _shotDataStore.FindBySubSessionId(currentSubSession.SessionSubtotalId) .Single(_ => _.Ordinal == e.Ordinal); currentSubSession.BestShotId = shot.ShotId; _sessionSubtotalDataStore.Update(currentSubSession); } }