public void Initialize(int shooterId) { ServiceDeskConfiguration sdk = ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>(); IShooterParticipationDataStore shooterParticipationDataStore = ServiceLocator.Current.GetInstance <IShooterParticipationDataStore>(); var programNumberToShooterParticipations = from sp in shooterParticipationDataStore.GetAll() join p in sdk.ParticipationDescriptions.GetAll() on sp.ProgramNumber.ToString() equals p.ProgramNumber where sp.ShooterId == shooterId group sp by p.ProgramNumber into gj select new { ProgramNumber = gj.Key, ShooterParticipations = gj.Select(x => x) }; var selectableParticipations = from p in sdk.ParticipationDescriptions.GetAll() where (!programNumberToShooterParticipations.Any(x => x.ProgramNumber == p.ProgramNumber) || !programNumberToShooterParticipations.Single(x => x.ProgramNumber == p.ProgramNumber) .ShooterParticipations.Any()) select p; ParticipationDescriptions = new ObservableCollection <ParticipationDescription>(selectableParticipations); }
private void LoadAvailableShooters() { IEnumerable <int> usedShooterIds = from s in _shooterDataStore.GetAll() join cs in _collectionShooterDataStore.GetAll() on s.ShooterId equals cs.ShooterId join scp in _shooterCollectionParticipationDataStore.GetAll() on cs.ShooterCollectionId equals scp.ShooterCollectionId where scp.ParticipationId == (SelectedUiParticipation == null ? 0 : SelectedUiParticipation.ParticipationId) select s.ShooterId; AvailableUiShooters = new ObservableCollection <UiShooter>( (from s in _shooterDataStore.GetAll() join sp in _shooterParticipationDataStore.GetAll() on s.ShooterId equals sp.ShooterId where sp.ParticipationId == (SelectedUiParticipation == null ? 0 : SelectedUiParticipation.ParticipationId) select s).Where(_ => usedShooterIds.All(s => s != _.ShooterId)) .Select(UiBusinessObjectMapper.ToUiShooter).Select(_ => _.FetchPerson(_personDataStore))); //if (SelectedUiShooterCollection != null) //{ // List<UiShooter> reducuedList = // AvailableUiShooters.Except(SelectedUiShooterCollection.Shooters, new UiShooterComparer()).ToList(); // AvailableUiShooters = new ObservableCollection<UiShooter>(reducuedList); //} }
private void ExecutePrintBarcodeCommand(UiShooter uiShooter) { try { bool isNachwuchs = (from sp in _shooterParticipationDataStore.GetAll() join p in _participationDataStore.GetAll() on sp.ParticipationId equals p.ParticipationId where p.ParticipationName == "Nachwuchsstich" && sp.ShooterId == uiShooter.ShooterId select p.ParticipationId). Any(); bool isGruppe = (from sp in _shooterParticipationDataStore.GetAll() join p in _participationDataStore.GetAll() on sp.ParticipationId equals p.ParticipationId where p.ParticipationName == "Gruppenstich" && sp.ShooterId == uiShooter.ShooterId select p.ParticipationId). Any(); bool isSieUndEr = (from sp in _shooterParticipationDataStore.GetAll() join p in _participationDataStore.GetAll() on sp.ParticipationId equals p.ParticipationId where p.ParticipationName == "Sie & Er" && sp.ShooterId == uiShooter.ShooterId select p.ParticipationId). Any(); bool isWorschtUndBrot = (from sp in _shooterParticipationDataStore.GetAll() join p in _participationDataStore.GetAll() on sp.ParticipationId equals p.ParticipationId where p.ParticipationName == "Worscht & Brot" && sp.ShooterId == uiShooter.ShooterId select p.ParticipationId). Any(); string groupName = (from cs in _collectionShooterDataStore.GetAll() join sc in _shooterCollectionDataStore.GetAll() on cs.ShooterCollectionId equals sc.ShooterCollectionId join scp in _shooterCollectionParticipationDataStore.GetAll() on cs.ShooterCollectionId equals scp.ShooterCollectionId join p in _participationDataStore.GetAll() on scp.ParticipationId equals p.ParticipationId where p.ParticipationName == "Gruppenstich" && cs.ShooterId == uiShooter.ShooterId select sc.CollectionName).SingleOrDefault(); string sieUndErName = (from cs in _collectionShooterDataStore.GetAll() join sc in _shooterCollectionDataStore.GetAll() on cs.ShooterCollectionId equals sc.ShooterCollectionId join scp in _shooterCollectionParticipationDataStore.GetAll() on cs.ShooterCollectionId equals scp.ShooterCollectionId join p in _participationDataStore.GetAll() on scp.ParticipationId equals p.ParticipationId where p.ParticipationName == "Sie & Er" && cs.ShooterId == uiShooter.ShooterId select sc.CollectionName).SingleOrDefault(); Person person = uiShooter.PersonId == null ? new Person() { FirstName = "unknown", LastName = "unknown" } : _personDataStore.FindById((int)uiShooter.PersonId); BarcodeHerbstschiessen barcodeInfo = new BarcodeHerbstschiessen { FirstName = person.FirstName, LastName = person.LastName, DateOfBirth = person.DateOfBirth, Gruppenstich = groupName ?? string.Empty, SieUndEr = sieUndErName ?? string.Empty, Barcode = _barcodeBuilderService.BuildBarcode(uiShooter.ShooterNumber, uiShooter.Legalization), IsGruppenstich = isGruppe, IsNachwuchsstich = isNachwuchs, IsWorschtUndBrot = isWorschtUndBrot, IsSieUndEr = isSieUndEr }; _barcodePrintService.Print(barcodeInfo); } catch (Exception e) { ReportException(e); } }
private IEnumerable <Tuple <Person, int, decimal, decimal> > GetBestResults(int programNumber) { IShooterDataStore shooterDataStore = ServiceLocator.Current.GetInstance <IShooterDataStore>(); IShooterParticipationDataStore shooterParticipationDataStore = ServiceLocator.Current.GetInstance <IShooterParticipationDataStore>(); ISessionDataStore sessionDataStore = ServiceLocator.Current.GetInstance <ISessionDataStore>(); ISessionSubtotalDataStore sessionSubtotalDataStore = ServiceLocator.Current.GetInstance <ISessionSubtotalDataStore>(); IShotDataStore shotDataStore = ServiceLocator.Current.GetInstance <IShotDataStore>(); IPersonDataStore personDataStore = ServiceLocator.Current.GetInstance <IPersonDataStore>(); List <Shooter> shooters = (from s in shooterDataStore.GetAll() join sp in shooterParticipationDataStore.GetAll() on s.ShooterId equals sp.ShooterId where sp.ProgramNumber == programNumber select s).ToList(); // Person, ShooterId, TotalScore, DeepShot List <Tuple <Person, int, decimal, decimal> > result = new List <Tuple <Person, int, decimal, decimal> >(); foreach (Shooter shooter in shooters) { // Get the relevant sessions var lShooter = shooter; IEnumerable <Session> sessions = from s in sessionDataStore.GetAll() where s.ShooterId == lShooter.ShooterId && s.ProgramNumber == programNumber select s; // Get the results to the sessions var maxScoreGrouping = from session in sessions join subTotal in sessionSubtotalDataStore.GetAll() on session.SessionId equals subTotal.SessionId join shot in shotDataStore.GetAll() on subTotal.SessionSubtotalId equals shot.SubtotalId group shot by session into grouping select new { Session = grouping.Key, TotalScore = grouping.Sum(x => x.PrimaryScore) }; // Get the max scores of each session var bestGrouping = maxScoreGrouping.OrderByDescending(x => x.TotalScore).FirstOrDefault(); if (bestGrouping != null) { // select the max score as the result which shall go into ranking decimal maxScore = bestGrouping.TotalScore; decimal?deepShot = (from subTotal in sessionSubtotalDataStore.GetAll() join shot in shotDataStore.GetAll() on subTotal.SessionSubtotalId equals shot.SubtotalId where subTotal.SessionId == bestGrouping.Session.SessionId orderby shot.SecondaryScore descending select shot.SecondaryScore).FirstOrDefault(); if (lShooter.PersonId.HasValue) { Person person = personDataStore.FindById(lShooter.PersonId.Value); result.Add(new Tuple <Person, int, decimal, decimal>(person, shooter.ShooterId, maxScore, deepShot ?? 0)); } } } return(result); }