public void Update(string demoChildData, DemoParent parent) { if (Key >= 0) { if (parent.Key < 0) { throw new Exception($"DemoChild.Update(): It is illegal to add stored DemoChild '{this}'" + Environment.NewLine + $"to Parent '{parent}', which is not stored."); } } var clone = new DemoChild(this); var isCancelled = false; onUpdating(demoChildData, parent, ref isCancelled); if (isCancelled) { return; } #if DEBUG DC.Trace?.Invoke($"Updating DemoChild: {ToTraceString()}"); #endif var isChangeDetected = false; if (DemoChildData != demoChildData) { DemoChildData = demoChildData; isChangeDetected = true; } if (Parent != parent) { Parent.RemoveFromDemoChildren(this); Parent = parent; Parent.AddToDemoChildren(this); isChangeDetected = true; } if (isChangeDetected) { onUpdated(clone); if (Key >= 0) { DC.Data.DemoChildren.ItemHasChanged(clone, this); } else if (DC.Data.IsTransaction) { DC.Data.AddTransaction(new TransactionItem(35, TransactionActivityEnum.Update, Key, this, oldItem: clone)); } HasChanged?.Invoke(clone, this); } #if DEBUG DC.Trace?.Invoke($"Updated DemoChild: {ToTraceString()}"); #endif }
public DemoChild(string demoChildData, DemoParent parent, bool isStoring = true) { Key = StorageExtensions.NoKey; DemoChildData = demoChildData; Parent = parent; #if DEBUG DC.Trace?.Invoke($"new DemoChild: {ToTraceString()}"); #endif Parent.AddToDemoChildren(this); onConstruct(); if (DC.Data?.IsTransaction ?? false) { DC.Data.AddTransaction(new TransactionItem(35, TransactionActivityEnum.New, Key, this)); } if (isStoring) { Store(); } }