void ObjectsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Remove) { try { foreach (object item in e.OldItems) { VariableConventionalPlantViewModel UIObject = item as VariableConventionalPlantViewModel; VariableThermalPlantsDataAccess.DeleteObject(UIObject.GetDataObject()); } } catch (Exception ex) { log.Error(ex.StackTrace); } } }
void ObjectsItemEndEdit(IEditableObject sender) { VariableConventionalPlantViewModel UIObject = sender as VariableConventionalPlantViewModel; try { if (UIObject.Name != null) { int id = VariableThermalPlantsDataAccess.UpdateObject(UIObject.GetDataObject()); if (id != -1) { UIObject.Id = id; } } } catch { UIObjects.Remove(UIObject); MessageBox.Show(MessageUtil.FormatMessage("ERROR.DuplicatedVariableThermalPlant", UIObject.Name, UIObject.Segment), "DHOG", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }