Beispiel #1
0
        private async Task AttachFiles(IEnumerable <IFormFile> files, Report report)
        {
            if (files != null)
            {
                var filesUploaded = await filesManager.Upload(files, $"reports/{report.Id}");

                filesUploaded.ToList().ForEach(f => report.ReportFiles.Add(ReportFile.Create <ReportFile>(f.Path)));

                await database.Complete();
            }
        }
Beispiel #2
0
        public ReportEditViewModel(IEventAggregator aggregator,
                                   IDataService <LabDbEntities> labDbData,
                                   IReportService reportService,
                                   IReportingService reportingService) : base()
        {
            _labDbData        = labDbData;
            _editMode         = false;
            _eventAggregator  = aggregator;
            _projectChanged   = false;
            _reportService    = reportService;
            _reportingService = reportingService;

            AddFileCommand = new DelegateCommand(
                () =>
            {
                OpenFileDialog fileDialog = new OpenFileDialog
                {
                    InitialDirectory = UserSettings.ReportPath,
                    Multiselect      = true
                };

                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    foreach (string pth in fileDialog.FileNames)
                    {
                        ReportFile temp  = new ReportFile();
                        temp.Path        = pth;
                        temp.Description = "";
                        temp.reportID    = _instance.ID;
                        temp.Create();
                    }

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

            AddTestsCommand = new DelegateCommand(
                () =>
            {
                if (_reportService.AddTestsToReport(_instance))
                {
                    TestList = new List <TestWrapper>(_instance.TestRecord.Tests.Select(tst => new TestWrapper(tst)));
                }
            },
                () => CanModify);

            GenerateRawDataSheetCommand = new DelegateCommand(
                () =>
            {
                _reportingService.PrintReportDataSheet(_instance);
            });

            OpenFileCommand = new DelegateCommand(
                () =>
            {
                try
                {
                    System.Diagnostics.Process.Start(_selectedFile.Path);
                }
                catch (Exception)
                {
                    _eventAggregator.GetEvent <StatusNotificationIssued>().Publish("File non trovato");
                }
            },
                () => _selectedFile != null);

            RemoveFileCommand = new DelegateCommand(
                () =>
            {
                _selectedFile.Delete();
                SelectedFile = null;

                RaisePropertyChanged("FileList");
            },
                () => CanModify && _selectedFile != null);

            RemoveTestCommand = new DelegateCommand <Test>(
                testItem =>
            {
                TaskItem tempTaskItem = testItem.GetTaskItem();
                testItem.Delete();

                if (tempTaskItem != null)
                {
                    throw new NotImplementedException();
                }

                TestList = new List <TestWrapper>(_instance.TestRecord.Tests.Select(tst => new TestWrapper(tst)));
            },
                testItem => EditMode);

            _save = new DelegateCommand(
                () =>
            {
                // Update the tests
                _testList.Select(tiw => tiw.TestInstance)
                .Update();

                // Update the report instance

                _instance.Update();

                // If the project was modified, update the material

                if (_projectChanged)
                {
                    _instance.SetProject(_selectedProject);
                }

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

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

            #region EventSubscriptions

            _eventAggregator.GetEvent <ProjectChanged>()
            .Subscribe(ect =>
            {
                _projectList = null;
                RaisePropertyChanged("ProjectList");
            });

            #endregion EventSubscriptions
        }