public CreateOnlyParentChangeableChild_Child( string readonlyText, string updatableText, CreateOnlyParentChangeableChild_Parent parent, CreateOnlyParentChangeableChild_ParentNullable?parentNullable, bool isStoring = true) { Key = StorageExtensions.NoKey; ReadonlyText = readonlyText; UpdatableText = updatableText; Parent = parent; ParentNullable = parentNullable; #if DEBUG DC.Trace?.Invoke($"new CreateOnlyParentChangeableChild_Child: {ToTraceString()}"); #endif Parent.AddToCreateOnlyParentChangeableChild_Children(this); if (ParentNullable != null) { ParentNullable.AddToCreateOnlyParentChangeableChild_Children(this); } onConstruct(); if (DC.Data?.IsTransaction ?? false) { DC.Data.AddTransaction(new TransactionItem(33, TransactionActivityEnum.New, Key, this)); } if (isStoring) { Store(); } }
partial void onUpdating(string updatableText, CreateOnlyParentChangeableChild_Parent parent, CreateOnlyParentChangeableChild_ParentNullable?parentNullable, ref bool isCancelled);
public void Update(string updatableText, CreateOnlyParentChangeableChild_Parent parent, CreateOnlyParentChangeableChild_ParentNullable?parentNullable) { if (Key >= 0) { if (parent.Key < 0) { throw new Exception($"CreateOnlyParentChangeableChild_Child.Update(): It is illegal to add stored CreateOnlyParentChangeableChild_Child '{this}'" + Environment.NewLine + $"to Parent '{parent}', which is not stored."); } if (parentNullable?.Key < 0) { throw new Exception($"CreateOnlyParentChangeableChild_Child.Update(): It is illegal to add stored CreateOnlyParentChangeableChild_Child '{this}'" + Environment.NewLine + $"to ParentNullable '{parentNullable}', which is not stored."); } } var clone = new CreateOnlyParentChangeableChild_Child(this); var isCancelled = false; onUpdating(updatableText, parent, parentNullable, ref isCancelled); if (isCancelled) { return; } #if DEBUG DC.Trace?.Invoke($"Updating CreateOnlyParentChangeableChild_Child: {ToTraceString()}"); #endif var isChangeDetected = false; if (UpdatableText != updatableText) { UpdatableText = updatableText; isChangeDetected = true; } if (Parent != parent) { Parent.RemoveFromCreateOnlyParentChangeableChild_Children(this); Parent = parent; Parent.AddToCreateOnlyParentChangeableChild_Children(this); isChangeDetected = true; } if (ParentNullable is null) { if (parentNullable is null) { //nothing to do } else { ParentNullable = parentNullable; ParentNullable.AddToCreateOnlyParentChangeableChild_Children(this); isChangeDetected = true; } } else { if (parentNullable is null) { ParentNullable.RemoveFromCreateOnlyParentChangeableChild_Children(this); ParentNullable = null; isChangeDetected = true; } else { if (ParentNullable != parentNullable) { ParentNullable.RemoveFromCreateOnlyParentChangeableChild_Children(this); ParentNullable = parentNullable; ParentNullable.AddToCreateOnlyParentChangeableChild_Children(this); isChangeDetected = true; } } } if (isChangeDetected) { onUpdated(clone); if (Key >= 0) { DC.Data.CreateOnlyParentChangeableChild_Children.ItemHasChanged(clone, this); } else if (DC.Data.IsTransaction) { DC.Data.AddTransaction(new TransactionItem(33, TransactionActivityEnum.Update, Key, this, oldItem: clone)); } HasChanged?.Invoke(clone, this); } #if DEBUG DC.Trace?.Invoke($"Updated CreateOnlyParentChangeableChild_Child: {ToTraceString()}"); #endif }