public void Initialize(Shooter shooter) { _shooterParticipationDataStore = ServiceLocator.Current.GetInstance <IShooterParticipationDataStore>(); _collectionShooterDataStore = ServiceLocator.Current.GetInstance <ICollectionShooterDataStore>(); _shooterCollectionDataStore = ServiceLocator.Current.GetInstance <IShooterCollectionDataStore>(); _sessionDataStore = ServiceLocator.Current.GetInstance <ISessionDataStore>(); _sessionSubtotalDataStore = ServiceLocator.Current.GetInstance <ISessionSubtotalDataStore>(); _shotDataStore = ServiceLocator.Current.GetInstance <IShotDataStore>(); _sdk = ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>(); SelectedGrouping = null; SelectedParticipation = null; Shooter = shooter; Participations = new ObservableCollection <ParticipationViewModel>(FetchParticipationsByShooter(Shooter)); Groupings = new ObservableCollection <GroupingViewModel>(FetchGroupsByShooter(Shooter)); SelectedPersonChanged(shooter.ShooterId); MessengerInstance.Register <RefreshDataFromRepositoriesMessage>(this, x => { Groupings = new ObservableCollection <GroupingViewModel>(FetchGroupsByShooter(Shooter)); Participations = new ObservableCollection <ParticipationViewModel>(FetchParticipationsByShooter(Shooter)); SelectedPersonChanged(Shooter.ShooterId); }); }
public void Initialize() { _personDataStore = ServiceLocator.Current.GetInstance <IPersonDataStore>(); _shooterDataStore = ServiceLocator.Current.GetInstance <IShooterDataStore>(); _sessionDataStore = ServiceLocator.Current.GetInstance <ISessionDataStore>(); _sessionSubtotalDataStore = ServiceLocator.Current.GetInstance <ISessionSubtotalDataStore>(); _shotDataStore = ServiceLocator.Current.GetInstance <IShotDataStore>(); _shooterParticipationDataStore = ServiceLocator.Current.GetInstance <IShooterParticipationDataStore>(); _sdk = ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>(); }
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); }
public void Initialize(int sessionId) { ServiceDeskConfiguration sdk = ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>(); Participations = new ObservableCollection <ParticipationViewModel>( from p in sdk.ParticipationDescriptions.GetAll() select new ParticipationViewModel { ProgramNumber = int.Parse(p.ProgramNumber), ProgramName = p.ProgramName }); }
public void Initialize() { _sdk = ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>(); Participations = new ObservableCollection <ParticipationViewModel> ( _sdk.ParticipationDescriptions.GetAll().Select(x => new ParticipationViewModel { ProgramNumber = int.Parse(x.ProgramNumber), ProgramName = x.ProgramName }) ); }
private static void InitializeServiceDeskConfiguration() { ServiceDeskConfiguration serviceDeskConfiguration = new ServiceDeskConfiguration(); Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (config.GetSection("ServiceDeskConfiguration") == null) { config.Sections.Add("ServiceDeskConfiguration", serviceDeskConfiguration); serviceDeskConfiguration.SectionInformation.ForceSave = true; config.Save(); } }
public CreateGroupingViewModel(ServiceDeskConfiguration serviceDeskConfiguration) { Participations = new ObservableCollection <ParticipationDescription>( serviceDeskConfiguration.ParticipationDescriptions.GetAll() .Where(x => x.AllowShooterCollectionParticipation)); OkCommand = new ViewModelCommand(x => { ((IWindow)x).Close(); }); OkCommand.AddGuard(x => !string.IsNullOrWhiteSpace(GroupingName) && SelectedParticipation != null); }
public void Initialize() { _personDataStore = ServiceLocator.Current.GetInstance <IPersonDataStore>(); _shooterDataStore = ServiceLocator.Current.GetInstance <IShooterDataStore>(); _shooterNumberService = ServiceLocator.Current.GetInstance <IShooterNumberService>(); _shooterDataWriter = ServiceLocator.Current.GetInstance <ISsvShooterDataWriterService>(); _collectionShooterDataStore = ServiceLocator.Current.GetInstance <ICollectionShooterDataStore>(); _shooterCollectionDataStore = ServiceLocator.Current.GetInstance <IShooterCollectionDataStore>(); _serviceDeskConfiguration = ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>(); MessengerInstance.Register <PersonSelectedMessage>(this, x => { UpdateCommandCanExecuteOnSelectedPersonChanged(); LoadShooters(x.PersonId); }); MessengerInstance.Register <SetSelectedPersonMessage>(this, x => { SelectedPerson = FilteredPersons.FirstOrDefault(person => person.PersonId == x.PersonId); }); MessengerInstance.Register <SetSelectedShooterMessage>(this, x => { SelectedShooter = Shooters.FirstOrDefault(s => s.Shooter.ShooterId == x.ShooterId); if (SelectedShooter == null) { SelectedShooter = Shooters.FirstOrDefault(); } }); MessengerInstance.Register <RefreshDataFromRepositoriesMessage>(this, x => { UiPerson selectedPerson = SelectedPerson; ShooterViewModel selectedShooter = SelectedShooter; LoadPersons(); if (selectedPerson != null) { MessengerInstance.Send(new SetSelectedPersonMessage(selectedPerson.PersonId)); } if (selectedShooter != null) { MessengerInstance.Send(new SetSelectedShooterMessage(selectedShooter.Shooter.ShooterId)); } }); }
private IEnumerable <ParticipationViewModel> FetchParticipationsByShooter(Shooter shooter) { ServiceDeskConfiguration sdk = ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>(); ParticipationDescriptionCollection participations = sdk.ParticipationDescriptions; return(from shooterParticipation in _shooterParticipationDataStore.FindByShooterId(shooter.ShooterId) join participation in participations.GetAll() on shooterParticipation.ProgramNumber.ToString() equals participation.ProgramNumber orderby participation.ProgramNumber select new ParticipationViewModel { ProgramName = participation.ProgramName, ProgramNumber = shooterParticipation.ProgramNumber }); }
public void Initialize() { ServiceDeskConfiguration sdk = ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>(); Groupings = new ObservableCollection <GroupingPageGroupingViewModel>(); foreach (ParticipationDescription participationDescription in sdk.ParticipationDescriptions.GetAll().Where(x => x.AllowShooterCollectionParticipation)) { GroupingPageGroupingViewModel groupingViewModel = new GroupingPageGroupingViewModel(); groupingViewModel.Initialize(); groupingViewModel.ProgramNumber = int.Parse(participationDescription.ProgramNumber); groupingViewModel.GroupingType = participationDescription.ProgramName; Groupings.Add(groupingViewModel); } }
private IEnumerable <GroupingViewModel> FetchGroupsByShooter(Shooter shooter) { ServiceDeskConfiguration sdk = ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>(); ParticipationDescriptionCollection participations = sdk.ParticipationDescriptions; return(from collectionShooter in _collectionShooterDataStore.FindByShooterId(shooter.ShooterId) join shooterCollection in _shooterCollectionDataStore.GetAll() on collectionShooter.ShooterCollectionId equals shooterCollection.ShooterCollectionId join participation in participations.GetAll() on shooterCollection.ProgramNumber.ToString() equals participation.ProgramNumber orderby shooterCollection.CollectionName select new GroupingViewModel { ShooterCollectionId = collectionShooter.CollectionShooterId, GroupingName = shooterCollection.CollectionName, ParticipationName = participation.ProgramName }); }
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); }
public static string GetProgramName(this ServiceDeskConfiguration serviceDeskConfiguration, int programNumber) { ParticipationDescription pd = serviceDeskConfiguration.ParticipationDescriptions.GetByKey(programNumber); return(pd == null?string.Format("unknown ({0})", programNumber) : pd.ProgramName); }
public void ConfigureContainer() { ShootingRangeEntities entities = new ShootingRangeEntities(); _messenger = new Messenger(); ContainerBuilder builder = new ContainerBuilder(); builder.RegisterInstance(_messenger).As <IMessenger>(); IShooterNumberService shooterNumberService = new ShooterNumberService(new ShooterNumberConfigDataStore(entities)); IPersonDataStore personDataStore = new PersonDataStore(entities); IShooterCollectionDataStore shooterCollectionDataStore = new ShooterCollectionDataStore(entities); ICollectionShooterDataStore collectionShooterDataStore = new CollectionShooterDataStore(entities); IShooterDataStore shooterDataStore = new ShooterDataStore(entities); IShooterParticipationDataStore shooterParticipationDataStore = new ShooterParticipationDataStore(entities); ISessionDataStore sessionDataStore = new SessionDataStore(entities); ISessionSubtotalDataStore sessionSubtotalDataStore = new SessionSubtotalDataStore(entities); IShotDataStore shotDataStore = new ShotDataStore(entities); IBarcodePrintService barcodePrinter = new PtouchBarcodePrinter(); IBarcodeBuilderService barcodeBuilder = new Barcode2Of5InterleavedService(); ISsvShooterDataWriterService shooterDataWriter = new SsvFileWriter(@"C:\Sius\SiusData\SSVDaten\SSV_schuetzen.txt"); builder.RegisterInstance(shooterNumberService).As <IShooterNumberService>(); builder.RegisterInstance(personDataStore).As <IPersonDataStore>(); builder.RegisterInstance(shooterDataStore).As <IShooterDataStore>(); builder.RegisterInstance(new ShooterParticipationDataStore(entities)).As <IShooterParticipationDataStore>(); builder.RegisterInstance(shooterCollectionDataStore).As <IShooterCollectionDataStore>(); builder.RegisterInstance(collectionShooterDataStore).As <ICollectionShooterDataStore>(); builder.RegisterInstance(sessionDataStore).As <ISessionDataStore>(); builder.RegisterInstance(sessionSubtotalDataStore).As <ISessionSubtotalDataStore>(); builder.RegisterInstance(shotDataStore).As <IShotDataStore>(); builder.RegisterInstance(barcodePrinter).As <IBarcodePrintService>(); builder.RegisterInstance(barcodeBuilder).As <IBarcodeBuilderService>(); builder.RegisterInstance(shooterDataWriter).As <ISsvShooterDataWriterService>(); _vs = new ViewService(); ViewServiceHandler vsh = new ViewServiceHandler(); #region Windows and Dialogs _vs.RegisterFunction <MainWindowViewModel, IWindow>( (window, model) => vsh.GetOwnedWindow <MainWindow>((Window)window, model)); #endregion _vs.RegisterFunction <PersonsPageViewModel, IPage>( (window, model) => vsh.GetUserControl <UcPersons>((Window)window, model)); _vs.RegisterFunction <GroupsPageViewModel, IPage>( (window, model) => vsh.GetUserControl <UcGroups>((Window)window, model)); _vs.RegisterFunction <ResultsPageViewModel, IPage>( (window, model) => vsh.GetUserControl <UcResults>((Window)window, model)); _vs.RegisterFunction <RankViewModel, IPage>( (window, model) => vsh.GetUserControl <UcRankings>((Window)window, model)); _vs.RegisterFunction <CreatePersonViewModel, IWindow>( (window, model) => vsh.GetOwnedWindow <CreatePerson>((Window)window, model)); _vs.RegisterFunction <CreateGroupingViewModel, IWindow>( (window, model) => vsh.GetOwnedWindow <CreateGrouping>((Window)window, model)); _vs.RegisterFunction <EditGroupingViewModel, IWindow>( (window, model) => vsh.GetOwnedWindow <EditGrouping>((Window)window, model)); _vs.RegisterFunction <SelectParticipationViewModel, IWindow>( (window, model) => vsh.GetOwnedWindow <AddParticipationToShooterDialog>((Window)window, model)); _vs.RegisterFunction <SelectGroupingViewModel, IWindow>( (window, model) => vsh.GetOwnedWindow <AddGroupingToShooterDialog>((Window)window, model)); _vs.RegisterFunction <SelectShooterViewModel, IWindow>( (window, model) => vsh.GetOwnedWindow <AddShooterToGroupingDialog>((Window)window, model)); _vs.RegisterFunction <ReassignSessionViewModel, IWindow>( (window, model) => vsh.GetOwnedWindow <ReassignSessionDialog>((Window)window, model)); _vs.RegisterFunction <ReassignProgramNumberViewModel, IWindow>( (window, model) => vsh.GetOwnedWindow <ReassignProgramNumber>((Window)window, model)); _vs.RegisterFunction <YesNoMessageBoxViewModel, IWindow>( (w, m) => vsh.GetOwnedWindow <YesNoMessageBox>((Window)w, m)); _vs.RegisterFunction <MessageBoxViewModel, IWindow>((w, m) => vsh.GetOwnedWindow <OkMessageBox>((Window)w, m)); InitializeServiceDeskConfiguration(); _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ServiceDeskConfiguration serviceDeskConfiguration = _config.GetSection("ServiceDeskConfiguration") as ServiceDeskConfiguration; if (serviceDeskConfiguration == null) { serviceDeskConfiguration = new ServiceDeskConfiguration(); _config.Sections.Add("ServiceDeskConfiguration", serviceDeskConfiguration); } builder.Register(c => serviceDeskConfiguration); IContainer container = builder.Build(); ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(container)); PersonsPageViewModel personsPageViewModel = new PersonsPageViewModel(); personsPageViewModel.Initialize(); GroupsPageViewModel groupsPageViewModel = new GroupsPageViewModel(); groupsPageViewModel.Initialize(); ResultsPageViewModel resultsPageViewModel = new ResultsPageViewModel(); resultsPageViewModel.Initialize(); RankViewModel rankViewModel = new RankViewModel(); rankViewModel.Initialize(); RegisterCreatePersonDialog(personDataStore); RegisterEditPersonDialog(personDataStore); RegisterCreateGroupingDialog(shooterCollectionDataStore, serviceDeskConfiguration); RegisterEditGroupingDialog(shooterCollectionDataStore); RegisterDeletePersonDialog(personDataStore); RegisterDeleteGroupingDialog(shooterCollectionDataStore); RegisterAddShooterToGroupingDialog(collectionShooterDataStore); RegisterDeleteShooterDialog(shooterDataStore); RegisterAddGroupingToShooterDialog(collectionShooterDataStore); RegisterRemoveGroupingFromShooterDialog(collectionShooterDataStore); RegisterAddParticipationToShooterDialog(shooterParticipationDataStore); RegisterRemoveParticipationFromShooterDialog(shooterParticipationDataStore); RegisterMessageBoxDialog(); RegisterReassignSessionDialog(sessionDataStore); RegisterReassignShooterNumberDialog(sessionDataStore); RegisterShowShooterPageMessage(personsPageViewModel); RegisterShowGroupsPageMessage(groupsPageViewModel); // RegisterShowResultsPageMessage(resultsPageViewModel); RegisterShowRankingsPageMessage(rankViewModel); }
private void RegisterCreateGroupingDialog(IShooterCollectionDataStore shooterCollectionDataStore, ServiceDeskConfiguration serviceDeskConfiguration) { _messenger.Register <CreateGroupingDialogMessage>(this, x => { var m = new CreateGroupingViewModel(serviceDeskConfiguration) { Title = "Gruppierung erstellen" }; IWindow w = _vs.ExecuteFunction <CreateGroupingViewModel, IWindow>((IWindow)Current.MainWindow, m); bool?result = w.ShowDialog(); if (!result.HasValue || !result.Value) { return; } ShooterCollection sc = new ShooterCollection { CollectionName = m.GroupingName, ProgramNumber = int.Parse(m.SelectedParticipation.ProgramNumber) }; shooterCollectionDataStore.Create(sc); _messenger.Send(new RefreshDataFromRepositoriesMessage()); }); }