private void __pView_AddNewSensor(object sender, EventArgs e) { AddEditSensorDialog pDialog = new AddEditSensorDialog(); pDialog.SetData(null, __pParamModels.ToList()); bool?bResult = pDialog.ShowDialog(); if (bResult.HasValue && bResult.Value) { try { FullSensorViewModel pData = pDialog.Data; Sensor pSensor = new Sensor(pData.MaterialNumber, pData.Name, pData.TestParam == null ? null : (long?)pData.TestParam.ID); //bool bSuccess =__pServiceProxy.AddSensor(pSensor); __pServiceProxy.AddSensor(pSensor); if (true) { __pSensorModels.Add(pData); } } catch (Exception ex) { //todo: Add logging } } }
private void __pView_EditSensor(object sender, SensorArgs e) { AddEditSensorDialog pDialog = new AddEditSensorDialog(); pDialog.SetData(e.Sensor, __pParamModels.ToList()); bool?bResult = pDialog.ShowDialog(); if (bResult.HasValue && bResult.Value) { FullSensorViewModel pData = pDialog.Data; Sensor pSensor = new Sensor(pData.MaterialNumber, pData.Name, pData.TestParam == null ? null : (long?)pData.TestParam.ID); bool bSuccess = __pServiceProxy.UpdateSensor(pSensor); if (bSuccess) { FullSensorViewModel pListSensor = __pSensorModels.FirstOrDefault(p => p.MaterialNumber == e.Sensor.MaterialNumber); if (pListSensor != null) { //This sucks, must be a better way to do this List <FullSensorViewModel> pNewSensorList = __pSensorModels.Except(new List <FullSensorViewModel> { pListSensor }).ToList(); pNewSensorList.Add(pData); __pSensorModels = new ObservableCollection <FullSensorViewModel>(pNewSensorList.OrderBy(p => p.MaterialNumber)); __pView.LoadSensorsPageData(__pSensorModels); } } } }