public ExternalReportEditViewModel(IEventAggregator aggregator, IDataService <LabDbEntities> labDbData, IReportService reportService) { _labDbData = labDbData; _editMode = false; _eventAggregator = aggregator; _reportService = reportService; AddBatchCommand = new DelegateCommand( () => { Batch tempBatch; BatchPickerDialog batchPicker = new BatchPickerDialog(); if (batchPicker.ShowDialog() == true) { tempBatch = _labDbData.RunQuery(new BatchQuery() { Number = batchPicker.BatchNumber }); _instance.AddBatch(tempBatch); RefreshTestRecords(); ResultColumnCollection = _instance.GetResultPresentationColumns(); } }, () => _instance != null && EditMode); AddFileCommand = new DelegateCommand( () => { OpenFileDialog fileDialog = new OpenFileDialog { InitialDirectory = UserSettings.ExternalReportPath, Multiselect = true }; if (fileDialog.ShowDialog() == DialogResult.OK) { foreach (string pth in fileDialog.FileNames) { ExternalReportFile temp = new ExternalReportFile(); temp.Path = pth; temp.Description = ""; temp.ExternalReportID = _instance.ID; temp.Create(); } RaisePropertyChanged("ReportFiles"); } }, () => EditMode); AddMethodCommand = new DelegateCommand <MethodVariant>( mtd => { _instance.AddTestMethod(mtd); _instance.MethodVariants.Add(mtd); RaisePropertyChanged("MethodVariantList"); RefreshTestRecords(); }, mtd => EditMode); OpenBatchCommand = new DelegateCommand( () => { NavigationToken token = new NavigationToken(MaterialViewNames.BatchInfoView, _selectedRecord.Batch); _eventAggregator.GetEvent <NavigationRequested>().Publish(token); }, () => _selectedRecord != null); OpenFileCommand = new DelegateCommand( () => { System.Diagnostics.Process.Start(_selectedFile.Path); }, () => _selectedFile != null); RemoveBatchCommand = new DelegateCommand( () => { _selectedRecord.Delete(); SelectedRecord = null; RefreshTestRecords(); ResultColumnCollection = _instance.GetResultPresentationColumns(); }, () => _selectedRecord != null && EditMode); RemoveFileCommand = new DelegateCommand( () => { _selectedFile.Delete(); SelectedFile = null; }, () => _selectedFile != null && EditMode); RemoveMethodCommand = new DelegateCommand <MethodVariant>( mtd => { _instance.RemoveTestMethodVariant(mtd); _instance.MethodVariants.Remove(mtd); RaisePropertyChanged("MethodVariantList"); RefreshTestRecords(); }, mtd => EditMode); SaveCommand = new DelegateCommand( () => { _instance.Update(true); EditMode = false; EntityChangedToken token = new EntityChangedToken(_instance, EntityChangedToken.EntityChangedAction.Updated); _eventAggregator.GetEvent <ExternalReportChanged>() .Publish(token); }, () => _editMode); StartEditCommand = new DelegateCommand( () => { EditMode = true; }, () => !_editMode && CanModify); }