public static bool IsDirty(IEditableBusinessObject entity) { if (entity == null) { return(true); } return(entity.IsDirty); }
public static void MarkOld(IEditableBusinessObject entity) { if (entity == null) { return; } entity.MarkOld(); }
/// <summary> /// Merges state from source graph into target graph. /// </summary> /// <param name="target">Target of merge.</param> /// <param name="source">Source for merge.</param> public void MergeGraph(IEditableBusinessObject target, IEditableBusinessObject source) { if (target is IManageProperties imp) { var targetProperties = imp.GetManagedProperties(); foreach (var item in targetProperties) { var sourceValue = ReadProperty(source, item); if (sourceValue is IEditableBusinessObject sourceChild) { if (ReadProperty(target, item) is IEditableBusinessObject targetChild) { MergeGraph(targetChild, sourceChild); } else { LoadProperty(target, item, sourceChild); } } else { if (sourceValue is IEditableCollection sourceList) { var targetList = ReadProperty(target, item) as IEditableCollection; MergeGraph(targetList, sourceList); } else { LoadProperty(target, item, sourceValue); } } } if (source.IsNew) { MarkNew(target); } else if (!source.IsDirty) { MarkOld(target); } else { CopyField(source, target, "_isDirty"); CopyField(source, target, "_isNew"); CopyField(source, target, "_isDeleted"); } CheckRules(target); } }
/// <summary> /// Merges state from source graph into target graph. /// </summary> /// <param name="target">Target of merge.</param> /// <param name="source">Source for merge.</param> public void MergeGraph(IEditableBusinessObject target, IEditableBusinessObject source) { var imp = target as IManageProperties; if (imp != null) { var targetProperties = imp.GetManagedProperties(); foreach (var item in targetProperties) { var sourceValue = ReadProperty(source, item); var sourceChild = sourceValue as IEditableBusinessObject; if (sourceChild != null) { var targetChild = ReadProperty(target, item) as IEditableBusinessObject; if (targetChild != null) { MergeGraph(targetChild, sourceChild); } else { LoadProperty(target, item, sourceChild); } } else { var sourceList = sourceValue as IEditableCollection; if (sourceList != null) { var targetList = ReadProperty(target, item) as IEditableCollection; MergeGraph(targetList, sourceList); } else { LoadProperty(target, item, sourceValue); } } } if (source.IsNew) { MarkNew(target); } else if (!source.IsDirty) { MarkOld(target); } CheckRules(target); } }
/// <summary> /// Refreshes the control's property /// values to reflect the values of /// the underlying business object. /// </summary> public void Refresh() { // per-type rules if (DataObject != null) { Type sourceType = DataObject.GetType(); var newValue = Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.CreateObject, DataObject); if (CanCreateObject != newValue) { CanCreateObject = newValue; } newValue = Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.GetObject, DataObject); if (CanGetObject != newValue) { CanGetObject = newValue; } newValue = Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.EditObject, DataObject); if (CanEditObject != newValue) { CanEditObject = newValue; } newValue = Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.DeleteObject, DataObject); if (CanDeleteObject != newValue) { CanDeleteObject = newValue; } } else { CanCreateObject = false; CanGetObject = false; CanEditObject = false; CanDeleteObject = false; } IEditableBusinessObject source = DataObject as IEditableBusinessObject; if (source != null) { if (IsDeleted != source.IsDeleted) { IsDeleted = source.IsDeleted; } if (IsDirty != source.IsDirty) { IsDirty = source.IsDirty; } if (IsNew != source.IsNew) { IsNew = source.IsNew; } if (IsSavable != source.IsSavable) { IsSavable = source.IsSavable; } if (IsValid != source.IsValid) { IsValid = source.IsValid; } } else { IEditableCollection sourceList = DataObject as IEditableCollection; if (sourceList != null) { if (IsDirty != sourceList.IsDirty) { IsDirty = sourceList.IsDirty; } if (IsValid != sourceList.IsValid) { IsValid = sourceList.IsValid; } if (IsSavable != sourceList.IsSavable) { IsSavable = sourceList.IsSavable; } IsDeleted = false; IsNew = false; } } }
/// <summary> /// Merges state from source graph into target graph. /// </summary> /// <param name="target">Target of merge.</param> /// <param name="source">Source for merge.</param> public void MergeGraph(IEditableBusinessObject target, IEditableBusinessObject source) { if (target is IManageProperties imp) { FieldManager.FieldDataManager targetFieldManager = null; if (target is IUseFieldManager iufm) { targetFieldManager = iufm.FieldManager; } FieldManager.FieldDataManager sourceFieldManager = null; if (source is IUseFieldManager iufms) { sourceFieldManager = iufms.FieldManager; } var targetProperties = imp.GetManagedProperties(); foreach (var item in targetProperties) { var sourceFieldExists = true; if (sourceFieldManager != null && (item.RelationshipType & RelationshipTypes.LazyLoad) == RelationshipTypes.LazyLoad) { sourceFieldExists = sourceFieldManager.FieldExists(item); } object sourceValue = null; if (sourceFieldExists) { sourceValue = ReadProperty(source, item); } if (sourceValue is IEditableBusinessObject sourceChild) { var targetFieldExists = true; if (targetFieldManager != null && (item.RelationshipType & RelationshipTypes.LazyLoad) == RelationshipTypes.LazyLoad) { targetFieldExists = targetFieldManager.FieldExists(item); } if (targetFieldExists && ReadProperty(target, item) is IEditableBusinessObject targetChild) { MergeGraph(targetChild, sourceChild); } else { if ((item.RelationshipType & RelationshipTypes.PrivateField) == RelationshipTypes.PrivateField) { Csla.Reflection.MethodCaller.CallPropertySetter(target, item.Name, sourceChild); } else { LoadProperty(target, item, sourceChild); } } } else { if (sourceValue is IEditableCollection sourceList) { var targetFieldExists = true; if (targetFieldManager != null && (item.RelationshipType & RelationshipTypes.LazyLoad) == RelationshipTypes.LazyLoad) { targetFieldExists = targetFieldManager.FieldExists(item); } if (targetFieldExists && ReadProperty(target, item) is IEditableCollection targetList) { MergeGraph(targetList, sourceList); } else { if ((item.RelationshipType & RelationshipTypes.PrivateField) == RelationshipTypes.PrivateField) { Csla.Reflection.MethodCaller.CallPropertySetter(target, item.Name, sourceList); } else { LoadProperty(target, item, sourceList); } } } else { if ((item.RelationshipType & RelationshipTypes.PrivateField) == RelationshipTypes.PrivateField) { Csla.Reflection.MethodCaller.CallPropertySetter(target, item.Name, sourceValue); } else { LoadProperty(target, item, sourceValue); } } } } if (source.IsNew) { MarkNew(target); } else if (!source.IsDirty) { MarkOld(target); } else { CopyField(source, target, "_isDirty"); CopyField(source, target, "_isNew"); CopyField(source, target, "_isDeleted"); } CheckRules(target); } }
/// <summary> /// This method is called by a child object when it /// wants to be removed from the collection. /// </summary> /// <param name="child">The child object to remove.</param> void IEditableCollection.RemoveChild(IEditableBusinessObject child) { Remove((C)child); }
/// <summary> /// Refreshes the control's property /// values to reflect the values of /// the underlying business object. /// </summary> public void Refresh() { // per-type rules if (DataObject != null) { Type sourceType = DataObject.GetType(); if (CanCreateObject != YYT.Security.AuthorizationRules.CanCreateObject(sourceType)) { CanCreateObject = YYT.Security.AuthorizationRules.CanCreateObject(sourceType); } if (CanGetObject != YYT.Security.AuthorizationRules.CanGetObject(sourceType)) { CanGetObject = YYT.Security.AuthorizationRules.CanGetObject(sourceType); } if (CanEditObject != YYT.Security.AuthorizationRules.CanEditObject(sourceType)) { CanEditObject = YYT.Security.AuthorizationRules.CanEditObject(sourceType); } if (CanDeleteObject != YYT.Security.AuthorizationRules.CanDeleteObject(sourceType)) { CanDeleteObject = YYT.Security.AuthorizationRules.CanDeleteObject(sourceType); } } else { CanCreateObject = false; CanGetObject = false; CanEditObject = false; CanDeleteObject = false; } IEditableBusinessObject source = DataObject as IEditableBusinessObject; if (source != null) { if (IsDeleted != source.IsDeleted) { IsDeleted = source.IsDeleted; } if (IsDirty != source.IsDirty) { IsDirty = source.IsDirty; } if (IsNew != source.IsNew) { IsNew = source.IsNew; } if (IsSavable != source.IsSavable) { IsSavable = source.IsSavable; } if (IsValid != source.IsValid) { IsValid = source.IsValid; } } else { IEditableCollection sourceList = DataObject as IEditableCollection; if (sourceList != null) { if (IsDirty != sourceList.IsDirty) { IsDirty = sourceList.IsDirty; } if (IsValid != sourceList.IsValid) { IsValid = sourceList.IsValid; } if (IsSavable != sourceList.IsSavable) { IsSavable = sourceList.IsSavable; } IsDeleted = false; IsNew = false; } } }