private void SetLastUpdater(object obj, string userId) { DbObjectInfo dbObjectInfo = DbObjectTools.GetDbObjectInfo(obj.GetType()); if (DbObjectTools.GetDynamicPropertyInfo(obj.GetType(), "LastUpdateUserId") != null) { ((DbObject)obj).SetValue <string>("LastUpdateUserId", userId); } }
public static List <string> GetModelNames(Module module) { List <string> list = new List <string>(); foreach (Type type in module.GetTypes()) { DbObjectInfo dbObjectInfo = DbObjectTools.GetDbObjectInfo(type); list.Add(dbObjectInfo.TableName); } return(list); }
public void Delete <T>(string id) where T : DbObject, new() { IDbObjectInfo <T> dbObjectInfo = this.DbRuleContext.GetDbObjectInfo <T>(); DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(typeof(T)), true); T model = this.QueryObject <T>(pkDynamicPropertyInfo.DataFieldName, id, true); dbObjectInfo.SetModifyDatetime(model); if (dbObjectInfo.IsLogicalDelete) { dbObjectInfo.SetLogicalDelete(model); this.DbObjectOperator.Update(model); } else { this.DbObjectOperator.Delete(model); } }
public virtual DbObject Update(User user, string objXml) { DbObject obj2 = this.Parse(objXml); DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(obj2.GetType()), true); string arg = obj2.GetValue(pkDynamicPropertyInfo.PropertyName).ToString(); SqlStringBuilder builder = new SqlStringBuilder(pkDynamicPropertyInfo.DataFieldName); builder.AppendFormat(" = '{0}'", arg); DbObject des = this.InvokeGenericMethod(this.DbContext, obj2.GetType(), "QueryObject", new Type[] { typeof(string), typeof(bool) }, new object[] { builder.ToString(), true }) as DbObject; if (user != null) { this.SetLastUpdater(obj2, user.Id); } A.Commons.Utils.CloneUtils.CloneObjectIgnoreId(obj2, des); this.InvokeGenericMethod(this.DbContext, obj2.GetType(), "Update", new Type[] { obj2.GetType() }, new object[] { des }); return(des); }
public virtual void Remove(string objXml) { DbObject obj2 = this.Parse(objXml); DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(obj2.GetType()), true); string str = obj2.GetValue(pkDynamicPropertyInfo.PropertyName).ToString(); this.InvokeGenericMethod(this.DbContext, obj2.GetType(), "Delete", new Type[] { typeof(string) }, new object[] { str }); }
private void BindUpdateCloneFunction() { this.UpdateCloneFunction = null; if (this.UpdateExceptFields.Count > 0) { Func <T, T, T> cloneFunction = this.GetCloneModelFunction((from t in this.UpdateExceptFields select t.ObjectFieldName).ToArray <string>()); this.UpdateCloneFunction = delegate(IDbContext context, T model, string[] updateFields) { Func <T, T, T> cloneModelFunction = cloneFunction; if (updateFields != null) { cloneModelFunction = this.GetCloneModelFunction((from t in this.AllFields where this.UpdateExceptFields.Contains(t) || (!t.ReadOnly && !updateFields.Contains <string>(t.ObjectFieldName)) select t.ObjectFieldName).ToArray <string>()); } DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(typeof(T)), true); object obj2 = model.GetValue(pkDynamicPropertyInfo.PropertyName); T local = context.QueryObject <T>(pkDynamicPropertyInfo.DataFieldName, obj2, true); cloneModelFunction(model, local); return(local); }; } }
private void BindRemoveCloneFunction() { Func <PropertyInfo, bool> predicate = null; Func <DataFieldAttribute, bool> func2 = null; this.RemoveCloneFunction = null; if (this.LogicalDeleteField != null) { if (predicate == null) { predicate = p => p.Name == LogicalDeleteField.ObjectFieldName; } PropertyInfo property = this.PropertyInfos.FirstOrDefault <PropertyInfo>(predicate); if (func2 == null) { func2 = f => f.ObjectFieldName != LogicalDeleteField.ObjectFieldName; } DataFieldAttribute[] attributeArray = this.AllFields.Where <DataFieldAttribute>(func2).ToArray <DataFieldAttribute>(); Func <T, T, T> cloneFunction = this.GetCloneModelFunction((from t in attributeArray select t.ObjectFieldName).ToArray <string>()); this.RemoveCloneFunction = delegate(IDbContext context, T model) { DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(typeof(T)), true); object obj2 = model.GetValue(pkDynamicPropertyInfo.PropertyName); T local = context.QueryObject <T>(pkDynamicPropertyInfo.DataFieldName, obj2, false); if (local != null) { cloneFunction(model, local); property.SetValue(local, true, null); property.SetValue(model, true, null); } return(local); }; } }