public CalibrationReportEditViewModel(IDataService <LabDbEntities> labDbData,
                                              IEventAggregator eventAggregator,
                                              InstrumentService instrumentService)
        {
            _labDbData         = labDbData;
            _editMode          = false;
            _instrumentService = instrumentService;

            _eventAggregator = eventAggregator;

            LabList = _labDbData.RunQuery(new OrganizationsQuery()
            {
                Role = OrganizationsQuery.OrganizationRoles.CalibrationLab
            })
                      .ToList();
            CalibrationResultList = _instrumentService.GetCalibrationResults();
            TechList = _labDbData.RunQuery(new PeopleQuery()
            {
                Role = PeopleQuery.PersonRoles.CalibrationTech
            })
                       .ToList();

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

                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    IEnumerable <CalibrationFiles> fileList = fileDialog.FileNames
                                                              .Select(file => new CalibrationFiles()
                    {
                        ReportID    = _calibrationInstance.ID,
                        Path        = file,
                        Description = ""
                    });

                    _instrumentService.AddCalibrationFiles(fileList);
                    RaisePropertyChanged("FileList");
                }
            });

            AddReferenceCommand = new DelegateCommand <string>(
                code =>
            {
                Instrument tempRef = _labDbData.RunQuery(new InstrumentQuery()
                {
                    Code = code
                });
                if (tempRef != null)
                {
                    _calibrationInstance.AddReference(tempRef);
                    ReferenceCode = "";
                    RaisePropertyChanged("ReferenceList");
                }
            });

            CancelEditCommand = new DelegateCommand(
                () =>
            {
                CalibrationInstance = _labDbData.RunQuery(new CalibrationReportsQuery()).FirstOrDefault(crep => crep.ID == _calibrationInstance.ID);
            },
                () => EditMode);

            DeleteCommand = new DelegateCommand(
                () =>
            {
                _calibrationInstance.Delete();
            },
                () => Thread.CurrentPrincipal.IsInRole(UserRoleNames.InstrumentAdmin));

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

            RemoveFileCommand = new DelegateCommand(
                () =>
            {
                _labDbData.Execute(new DeleteEntityCommand(_selectedFile));

                RaisePropertyChanged("FileList");

                SelectedFile = null;
            },
                () => _selectedFile != null);

            RemoveReferenceCommand = new DelegateCommand(
                () =>
            {
                _calibrationInstance.RemoveReference(SelectedReference);
                SelectedReference = null;
                RaisePropertyChanged("ReferenceList");
            },
                () => SelectedReference != null);

            SaveCommand = new DelegateCommand(
                () =>
            {
                _calibrationInstance.Update();
                foreach (CalibrationReportInstrumentPropertyMapping cripmw in PropertyMappingList)
                {
                    cripmw.Update();
                }

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

            _startEdit = new DelegateCommand(
                () =>
            {
                EditMode = true;
            },
                () => !EditMode);
        }