public static void Update(this CalibrationReportInstrumentPropertyMapping entry) { // Updates a CAlibrationReportInstrumentPropertyMapping entry using (LabDbEntities entities = new LabDbEntities()) { entities.CalibrationReportInstrumentPropertyMappings.AddOrUpdate(entry); entities.SaveChanges(); } }
public NewCalibrationDialogViewModel(LabDbEntities entities, IEventAggregator eventAggregator, InstrumentService instrumentService, IDataService <LabDbEntities> labDbData) : base() { _labDbData = labDbData; _entities = entities; _instrumentService = instrumentService; IsVerificationOnly = false; ReferenceList = new ObservableCollection <Instrument>(); LabList = _labDbData.RunQuery(new OrganizationsQuery() { Role = OrganizationsQuery.OrganizationRoles.CalibrationLab }) .ToList(); _eventAggregator = eventAggregator; CalibrationDate = DateTime.Now.Date; AddReferenceCommand = new DelegateCommand <string>( code => { Instrument tempRef = _entities.Instruments.FirstOrDefault(inst => inst.Code == code); if (tempRef != null) { ReferenceList.Add(tempRef); ReferenceCode = ""; } }); CancelCommand = new DelegateCommand <Window>( parentDialog => { parentDialog.DialogResult = false; }); ConfirmCommand = new DelegateCommand <Window>( parentDialog => { ReportInstance = new CalibrationReport(); ReportInstance.Date = CalibrationDate; ReportInstance.Year = DateTime.Now.Year - 2000; ReportInstance.Number = _instrumentService.GetNextCalibrationNumber(ReportInstance.Year); ReportInstance.Instrument = _instumentInstance; ReportInstance.IsVerification = IsVerificationOnly; ReportInstance.laboratoryID = _selectedLab.ID; ReportInstance.Notes = ""; ReportInstance.ResultID = 1; if (IsNotExternalLab) { ReportInstance.OperatorID = SelectedTech.ID; foreach (Instrument refInstrument in ReferenceList) { ReportInstance.ReferenceInstruments.Add(refInstrument); } } foreach (InstrumentMeasurableProperty imp in _instumentInstance.GetMeasurableProperties()) { CalibrationReportInstrumentPropertyMapping cripm = new CalibrationReportInstrumentPropertyMapping() { ExtendedUncertainty = 0, LowerRangeValue = imp.RangeLowerLimit, MeasurablePropertyID = imp.ID, MeasurementUnitID = imp.UnitID, UpperRangeValue = imp.RangeUpperLimit }; ReportInstance.InstrumentMeasurablePropertyMappings.Add(cripm); } _entities.CalibrationReports.Add(ReportInstance); _entities.SaveChanges(); parentDialog.DialogResult = true; }); RemoveReference = new DelegateCommand( () => { ReferenceList.Remove(_selectedReference); SelectedReference = null; }, () => _selectedReference != null); }