public InstrumentCreationDialogViewModel(IDataService <LabDbEntities> labDbData) : base() { _labDbData = labDbData; ControlPeriod = 12; Notes = ""; Model = ""; SerialNumber = ""; CalibrationLabList = _labDbData.RunQuery(new OrganizationsQuery() { Role = OrganizationsQuery.OrganizationRoles.CalibrationLab }) .ToList(); CancelCommand = new DelegateCommand <Window>( parent => { parent.DialogResult = false; }); ConfirmCommand = new DelegateCommand <Window>( parent => { InstrumentInstance = new Instrument(); InstrumentInstance.Code = _code; InstrumentInstance.Description = Notes; InstrumentInstance.InstrumentTypeID = SelectedType.ID; InstrumentInstance.IsInService = true; InstrumentInstance.IsUnderControl = _isUnderControl; InstrumentInstance.CalibrationInterval = ControlPeriod; InstrumentInstance.UtilizationAreaID = SelectedArea.ID; InstrumentInstance.CalibrationDueDate = (_isUnderControl) ? DateTime.Now : (DateTime?)null; InstrumentInstance.CalibrationResponsibleID = _selectedCalibrationLab?.ID; InstrumentInstance.manufacturerID = SelectedManufacturer.ID; InstrumentInstance.Model = Model; InstrumentInstance.SerialNumber = SerialNumber; foreach (MeasurableQuantity meq in SelectedType.GetAssociatedMeasurableQuantities()) { InstrumentMeasurableProperty tempIMP = new InstrumentMeasurableProperty() { MeasurableQuantityID = meq.ID, UnitID = meq.UnitsOfMeasurement.First().ID }; InstrumentInstance.InstrumentMeasurableProperties.Add(tempIMP); } InstrumentInstance.Create(); parent.DialogResult = true; }, parent => !HasErrors); SelectedCalibrationLab = null; }