public InstrumentMainViewModel(IDataService <LabDbEntities> labDbData, IEventAggregator eventAggregator, InstrumentService instrumentService) : base() { _eventAggregator = eventAggregator; _labDbData = labDbData; _instrumentService = instrumentService; DeleteInstrumentCommand = new DelegateCommand( () => { _selectedInstrument.Delete(); SelectedInstrument = null; }, () => IsInstrumentAdmin && _selectedInstrument != null); NewInstrumentCommand = new DelegateCommand( () => { _instrumentService.CreateInstrument(); }, () => IsInstrumentAdmin); OpenInstrumentCommand = new DelegateCommand( () => { NavigationToken token = new NavigationToken(InstrumentViewNames.InstrumentEditView, SelectedInstrument); _eventAggregator.GetEvent <NavigationRequested>().Publish(token); }, () => SelectedInstrument != null); OpenPendingCommand = new DelegateCommand( () => { NavigationToken token = new NavigationToken(InstrumentViewNames.InstrumentEditView, SelectedPending); _eventAggregator.GetEvent <NavigationRequested>().Publish(token); }); _eventAggregator.GetEvent <CalibrationIssued>().Subscribe( calRep => { RaisePropertyChanged("PendingCalibrationsList"); RaisePropertyChanged("CalibrationsList"); }); _eventAggregator.GetEvent <InstrumentListUpdateRequested>().Subscribe( () => { RaisePropertyChanged("InstrumentList"); RaisePropertyChanged("PendingCalibrationsList"); }); }
public InstrumentMainViewModel(IDataService <LInstContext> lInstData, IEventAggregator eventAggregator, InstrumentService instrumentService) : base() { _eventAggregator = eventAggregator; _lInstData = lInstData; _instrumentService = instrumentService; InstrumentList = _lInstData.RunQuery(new InstrumentsQuery()).ToList(); DeleteInstrumentCommand = new DelegateCommand( () => { DialogResult confirmation = MessageBox.Show("Lo strumento selezionato verrà eliminato, continuare?", "Conferma Eliminazione", MessageBoxButtons.YesNo); if (confirmation == DialogResult.Yes) { _lInstData.Execute(new DeleteEntityCommand <LInstContext>(_selectedInstrument)); SelectedInstrument = null; } }, () => IsInstrumentAdmin && _selectedInstrument != null); NewInstrumentCommand = new DelegateCommand( () => { _instrumentService.CreateInstrument(); }, () => IsInstrumentAdmin); OpenInstrumentCommand = new DelegateCommand( () => { NavigationToken token = new NavigationToken(InstrumentViewNames.InstrumentEditView, _lInstData.RunQuery(new InstrumentQuery() { ID = SelectedInstrument.ID })); _eventAggregator.GetEvent <NavigationRequested>().Publish(token); }, () => SelectedInstrument != null); OpenPendingCommand = new DelegateCommand( () => { NavigationToken token = new NavigationToken(InstrumentViewNames.InstrumentEditView, SelectedPending); _eventAggregator.GetEvent <NavigationRequested>().Publish(token); }); RunQueryCommand = new DelegateCommand( () => { RefreshList(); }); UpdateAllCalibrationStatusesCommand = new DelegateCommand( () => { _lInstData.Execute(new BulkUpdateInstrumentCalibrationStatusCommand(InstrumentList)); RefreshList(); }); _eventAggregator.GetEvent <CalibrationIssued>().Subscribe( calRep => { RaisePropertyChanged("PendingCalibrationsList"); RaisePropertyChanged("CalibrationsList"); }); _eventAggregator.GetEvent <InstrumentListUpdateRequested>().Subscribe( () => { RefreshList(); RaisePropertyChanged("PendingCalibrationsList"); }); }