Exemplo n.º 1
0
        public MethodEditViewModel(IEventAggregator aggregator,
                                   IDataService <LabDbEntities> labDbData,
                                   ISpecificationService specificationService) : base()
        {
            _labDbData            = labDbData;
            _editMode             = false;
            _eventAggregator      = aggregator;
            _specificationService = specificationService;

            OrganizationList = _labDbData.RunQuery(new OrganizationsQuery()
            {
                Role = OrganizationsQuery.OrganizationRoles.StandardPublisher
            })
                               .ToList();;
            PropertyList = _labDbData.RunQuery(new PropertiesQuery()).ToList();

            Measurements = new List <SubMethod>();

            AddFileCommand = new DelegateCommand(
                () =>
            {
                OpenFileDialog fileDialog = new OpenFileDialog
                {
                    Multiselect = true
                };

                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    foreach (string pth in fileDialog.FileNames)
                    {
                        StandardFile temp = new StandardFile
                        {
                            Path        = pth,
                            Description = "",
                            StandardID  = _methodInstance.StandardID
                        };

                        temp.Create();
                    }

                    RaisePropertyChanged("FileList");
                }
            },
                () => CanModify);

            CancelEditCommand = new DelegateCommand(
                () =>
            {
                EditMode = false;
            },
                () => EditMode);

            OpenFileCommand = new DelegateCommand(
                () =>
            {
                System.Diagnostics.Process.Start(_selectedFile.Path);
            },
                () => _selectedFile != null);

            OpenReportCommand = new DelegateCommand <Test>(
                tst =>
            {
                NavigationToken token = new NavigationToken((tst.TestRecord.RecordTypeID == 1) ? ReportViewNames.ReportEditView : ReportViewNames.ExternalReportEditView,
                                                            tst.TestRecord.Reports.First());

                _eventAggregator.GetEvent <NavigationRequested>()
                .Publish(token);
            });

            OpenSpecificationCommand = new DelegateCommand <Specification>(
                spec =>
            {
                NavigationToken token = new NavigationToken(SpecificationViewNames.SpecificationEdit,
                                                            spec);
                _eventAggregator.GetEvent <NavigationRequested>().Publish(token);
            });

            RemoveFileCommand = new DelegateCommand(
                () =>
            {
                _selectedFile.Delete();
                SelectedFile = null;
            },
                () => EditMode && _selectedFile != null);

            SaveCommand = new DelegateCommand(
                () =>
            {
                _methodInstance.Update();

                _specificationService.UpdateSubMethods(Measurements);
                _specificationService.UpdateMethodVariantRange(_methodVariantList);

                if (_selectedOrganization.ID != _methodInstance.Standard.OrganizationID)
                {
                    _methodInstance.Standard.OrganizationID = _selectedOrganization.ID;
                    _methodInstance.Standard.Update();
                }

                EditMode = false;
            },
                () => _editMode);

            StartEditCommand = new DelegateCommand(
                () =>
            {
                EditMode = true;
            },
                () => CanModify && !_editMode);

            UpdateCommand = new DelegateCommand(
                () =>
            {
                _specificationService.ModifyMethodTestList(_methodInstance);
            },
                () => CanModify);
        }