protected virtual bool Update(NamedObject ndo_changes, out NamedObject to_change) { string idProperty_Name = null; to_change = ResolveNDO(ndo_changes, out idProperty_Name); if (to_change != null) { ObjScope.Transaction.Begin(); foreach (PropertyInfo pi in ndo_changes.GetType().GetProperties()) { if (pi.Name == idProperty_Name) continue; // do not update Primary Property object v_changes = pi.GetValue(ndo_changes, null); if (v_changes != null && (pi.CanWrite || v_changes.GetType().IsGenericType)) SetProperty(to_change, pi, v_changes); } ObjScope.Transaction.Commit(); return true; } else return false; }
public virtual bool Add(NamedObject ndo_insert) { string idProperty_Name = null; object check_exist = ResolveNDO(ndo_insert, out idProperty_Name); if (check_exist == null) { foreach (PropertyInfo pi in ndo_insert.GetType().GetProperties()) { if (pi.Name == idProperty_Name) continue; // do not update Primary Property object v_changes = pi.GetValue(ndo_insert, null); if (v_changes != null && (pi.CanWrite || v_changes.GetType().IsGenericType)) SetProperty(ndo_insert, pi, v_changes); } ObjScope.Transaction.Begin(); ObjScope.Add(ndo_insert); ObjScope.Transaction.Commit(); return true; } else return false; }
protected NamedObject ResolveNDO(NamedObject ndo_changes, out string idProperty_Name) { object to_change = null; string idProperty_Value = Service.GetIdentityFieldValue(ndo_changes, out idProperty_Name); if (idProperty_Value == null || idProperty_Value == "0") to_change = ResolveCDO(ndo_changes.GetType(), ndo_changes.Name); else to_change = ResolveCDOByID(ndo_changes.GetType(), idProperty_Value); return to_change as NamedObject; }