public virtual string Remove() { DynamicJson dj = GetParam(); string resJson = string.Empty; string primaryKey = "Id"; try { JMI jmi = GetJMI(dj); using (DBAccessor dba = DBAccessor.Instance(Dbs.Get(jmi.DbsName))) { string condition = string.Empty; string sql = string.Empty; string tableName = TableName(jmi.DtoType); IList <string> cols = new List <string>(); if (GetPrimaryKey(jmi.DtoType).Count() > 0) { primaryKey = GetPrimaryKey(jmi.DtoType).FirstOrDefault().Name; } DbParameter[] paras = BuildParameter(jmi.DtoType, dba, dj, ref cols); int rows = dba.ExecuteCommand(string.Format("delete from {0} where {1}=:{1}", tableName, primaryKey), dba.CreateDbParameter(primaryKey, dj.Get(primaryKey)), false); if (rows > 0) { resJson = new { result = 1 } } .ToJson(); }
public virtual string Save() { try { DynamicJson dj = GetParam(); JMI jmi = GetJMI(dj); if (!dj.IsList && !dj.GetStr(JModelNo.AccessSaveListKey).IsNullOrEmpty()) { dj = dj.Get(JModelNo.AccessSaveListKey).ToJson().ToDynamicJson(); if (!jmi.TBCode.IsNullOrWhiteSpace()) { foreach (DynamicJson djItem in dj) { djItem.Set(JModelNo.AccessTableKey, jmi.TBCode); } } } using (DBAccessor dba = DBAccessor.Instance(Dbs.Get(jmi.DbsName))) { return(OnSave(dj, dba)); } } catch (Exception ex) { return(Loger.Log(Assembly.GetExecutingAssembly().FullName, MethodBase.GetCurrentMethod().FullName(), ex)); } }
/// <summary> /// 逻辑删除 post 数据格式类似为 { primaryKey: 1,2 } /// </summary> /// <returns></returns> public string Delete() { string json = GetPostData(); DynamicJson dj = GetParam(); JMI jmi = GetJMI(dj); if (!dj.IsList && !dj.GetStr(JModelNo.AccessSaveListKey).IsNullOrEmpty()) { dj = dj.Get(JModelNo.AccessSaveListKey).ToJson().ToDynamicJson(); if (!jmi.TBCode.IsNullOrWhiteSpace()) { foreach (DynamicJson djItem in dj) { djItem.Set(JModelNo.AccessTableKey, jmi.TBCode); } } } using (DBAccessor dba = DBAccessor.Instance(Dbs.Get(jmi.DbsName))) { return(OnSave(dj, dba, true)); } }