示例#1
0
        private void RegisterRemoveParticipationFromShooterDialog(IShooterParticipationDataStore shooterParticipationDataStore)
        {
            _messenger.Register <RemoveParticipationFromShooterDialogMessage>(this,
                                                                              x =>
            {
                YesNoMessageBoxViewModel vm = new YesNoMessageBoxViewModel
                {
                    Caption    = "Wettkampf löschen",
                    DefaultYes = false,
                    Message    =
                        string.Format("Wettkampfzuordnung '{0}' wirklich löschen?", x.Participation.ProgramName)
                };

                IWindow w   = _vs.ExecuteFunction <YesNoMessageBoxViewModel, IWindow>((IWindow)Current.MainWindow, vm);
                bool?result = w.ShowDialog();

                if (!result.HasValue || !result.Value)
                {
                    return;
                }

                ShooterParticipation shooterParticipation =
                    shooterParticipationDataStore.FindByShooterId(x.ShooterId)
                    .SingleOrDefault(sp => sp.ProgramNumber == x.Participation.ProgramNumber);
                shooterParticipationDataStore.Delete(shooterParticipation);

                _messenger.Send(new RefreshDataFromRepositoriesMessage());
            });
        }
        private void SelectedPersonChanged(int shooterId)
        {
            if (MessengerInstance == null)
            {
                return;
            }
            Dictionary <int, List <int> > sessionToSubsession = (from session in
                                                                 _sessionDataStore.FindByShooterId(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(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);
                }
            }
        }
        public void Initialize(int shooterId)
        {
            ServiceDeskConfiguration serviceDeskConfiguration =
                ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>();
            IShooterDataStore           shooterDataStore           = ServiceLocator.Current.GetInstance <IShooterDataStore>();
            IPersonDataStore            personDataStore            = ServiceLocator.Current.GetInstance <IPersonDataStore>();
            ICollectionShooterDataStore collectionShooterDataStore =
                ServiceLocator.Current.GetInstance <ICollectionShooterDataStore>();
            IShooterCollectionDataStore shooterCollectionDataStore =
                ServiceLocator.Current.GetInstance <IShooterCollectionDataStore>();
            IShooterParticipationDataStore shooterParticipationDataStore =
                ServiceLocator.Current.GetInstance <IShooterParticipationDataStore>();

            // Get PrgramNumbers in which the shooter is enroled.
            List <int> programNumbers = (from sp in shooterParticipationDataStore.FindByShooterId(shooterId)
                                         select sp.ProgramNumber).ToList();

            // Get all CollectionShooters grouped by their ShooterCollections Participation ProgramNumber
            IEnumerable <IGrouping <int, CollectionShooter> > collectionShootersGroupedByProgramNumber =
                from p in programNumbers
                join sc in shooterCollectionDataStore.GetAll() on p equals sc.ProgramNumber
                join
                cs in collectionShooterDataStore.GetAll() on sc.ShooterCollectionId equals cs.ShooterCollectionId
                group cs by p;

            // Program Numbers with which the current shooter is not yet enroled as a CollectionShooter
            IEnumerable <int> programNumbersAlreadyEnroled = from scg in collectionShootersGroupedByProgramNumber
                                                             where scg.Any(x => x.ShooterId == shooterId)
                                                             select scg.Key;

            // Final list of ShooterCollections which are relevant for the current shooter
            IEnumerable <ShooterCollection> shooterCollectionsFinal = from p in programNumbers
                                                                      join sc in shooterCollectionDataStore.GetAll() on p equals sc.ProgramNumber
                                                                      where !programNumbersAlreadyEnroled.Contains(p)
                                                                      select sc;

            IEnumerable <GroupingViewModel> groupingViewModels = from sc in shooterCollectionsFinal
                                                                 join p in serviceDeskConfiguration.ParticipationDescriptions.GetAll() on sc.ProgramNumber.ToString()
                                                                 equals
                                                                 p.ProgramNumber
                                                                 select new GroupingViewModel
            {
                ShooterCollectionId = sc.ShooterCollectionId,
                GroupingName        = sc.CollectionName,
                ParticipationName   = p.ProgramName,
                Shooters            =
                    new ObservableCollection <PersonShooterViewModel>(from cs in collectionShooterDataStore.GetAll()
                                                                      join s in shooterDataStore.GetAll() on cs.ShooterId equals s.ShooterId
                                                                      join person in personDataStore.GetAll() on s.PersonId equals person.PersonId
                                                                      where cs.ShooterCollectionId == sc.ShooterCollectionId
                                                                      select new PersonShooterViewModel(person, s))
            };

            Groupings = new ObservableCollection <GroupingViewModel>(groupingViewModels);
        }
示例#4
0
        private void LoadParticipationList()
        {
            try
            {
                Func <ParticipationDetails, ParticipationTreeItem> selector =
                    (gmd) =>
                    new ParticipationTreeItem
                {
                    ParticipationNames       = gmd.ParticipationNames,
                    ParticipationDescription = gmd.ParticipationDescription
                };

                //IEnumerable<ParticipationTreeItem> participationTreeItems;
                List <ShooterParticipationDetails> participations = new List <ShooterParticipationDetails>();
                if (SelectedUiShooter != null)
                {
                    //participationTreeItems = _groupDetailsView.FindByShooterId(SelectedAvailableUiShooter.ShooterId).Select(selector);
                    //participations = _shooterParticipationView.FindByShooterId(SelectedAvailableUiShooter.ShooterId);
                    IEnumerable <ShooterParticipation> shooterParticipations =
                        _shooterParticipationDataStore.FindByShooterId(SelectedUiShooter.ShooterId).ToList();
                    foreach (ShooterParticipation shooterParticipation in shooterParticipations)
                    {
                        Participation participation = _participationDataStore.FindById(shooterParticipation.ParticipationId);
                        participations.Add(new ShooterParticipationDetails
                        {
                            ParticipationName      = participation.ParticipationName,
                            ShooterParticipationId = shooterParticipation.ShooterParticipationId
                        });
                    }
                }
                //else if (SelectedUiPerson != null)
                //{
                //  //participationTreeItems = _groupDetailsView.FindByPersonId(SelectedUiPerson.PersonId).Select(selector);
                //}
                //else
                //{
                //  //participationTreeItems = _groupDetailsView.GetAll().Select(selector);
                //  IEnumerable<ShooterParticipation> shooterParticipations = _shooterParticipationDataStore.GetAll().ToList();
                //  foreach (ShooterParticipation shooterParticipation in shooterParticipations)
                //  {
                //    Participation participation = _participationDataStore.FindById(shooterParticipation.ParticipationId);
                //    participations.Add(new ShooterParticipationDetails
                //    {
                //      ParticipationName = participation.ParticipationName,
                //      ShooterParticipationId = shooterParticipation.ShooterParticipationId
                //    });
                //  }
                //}

                Participations =
                    new ObservableCollection <ShooterParticipationListItem>(
                        participations.OrderBy(_ => _.ParticipationName).Select(_ => new ShooterParticipationListItem
                {
                    ParticipationName      = _.ParticipationName,
                    ShooterParticipationId = _.ShooterParticipationId,
                }));
            }
            catch (Exception e)
            {
                ReportException(e);
            }
            //ParticipationTreeItems = new ObservableCollection<ParticipationTreeItem>(participationTreeItems.Where(_ => _.ParticipationNames.Any()));
        }
示例#5
0
        private void RegisterRemoveParticipationFromShooterDialog(IShooterParticipationDataStore shooterParticipationDataStore)
        {
            _messenger.Register<RemoveParticipationFromShooterDialogMessage>(this,
                x =>
                {
                    YesNoMessageBoxViewModel vm = new YesNoMessageBoxViewModel
                    {
                        Caption = "Wettkampf löschen",
                        DefaultYes = false,
                        Message =
                            string.Format("Wettkampfzuordnung '{0}' wirklich löschen?", x.Participation.ProgramName)
                    };

                    IWindow w = _vs.ExecuteFunction<YesNoMessageBoxViewModel, IWindow>((IWindow) Current.MainWindow, vm);
                    bool? result = w.ShowDialog();

                    if (!result.HasValue || !result.Value) return;

                    ShooterParticipation shooterParticipation =
                        shooterParticipationDataStore.FindByShooterId(x.ShooterId)
                            .SingleOrDefault(sp => sp.ProgramNumber == x.Participation.ProgramNumber);
                    shooterParticipationDataStore.Delete(shooterParticipation);

                    _messenger.Send(new RefreshDataFromRepositoriesMessage());
                });
        }