internal static string ConstructUpdateUpdatedQuery(this DirectModel model) { if (model.IntegerPrimary && !model.ID.HasValue) { throw new Exception("ID is not set, maybe this table was not loaded"); } model.OnBeforeUpdate(); // UPDATE MobilePaywall.core.A SET A=1 WHERE AID=1 string updatedPropName = string.Empty; foreach (var prop in model.Snapshot.PropertySignatures) { if (prop.Name.ToLower().Equals("updated")) { updatedPropName = prop.Name; } } if (string.IsNullOrEmpty(updatedPropName)) { return(string.Empty); } string command = string.Format(DirectModelHelper.GetDatabase(model).QueryConstructUpdateUpdatedQuery, model.GetTableName(), updatedPropName, model.GetDatabase().ConstructDateTimeParam(DateTime.Now), model.GetIdNameValue(), (model.IntegerPrimary ? model.ID.Value.ToString() : string.Format("'{0}'", model.GetStringID()))); return(command); }
public static async Task <int?> UpdateAsync(this DirectDatabaseBase db, DirectModel model) { if (model.IntegerPrimary && !model.ID.HasValue) { throw new Exception("ID is not set, maybe this table was not loaded"); } // UPDATE MobilePaywall.core.A SET A=1 WHERE AID=1 string command = string.Format(DirectModelHelper.GetDatabase(model).QueryConstructUpdateQuery, model.GetTableName(), model.Snapshot.GetUpdateData(), model.GetIdNameValue(), (model.IntegerPrimary ? model.ID.Value.ToString() : string.Format("'{0}'", model.GetStringID()))); DirectExecuteResult result = await db.ExecuteAsync(command); if (!result.IsSuccessfull) { return(null); } else { model.Snapshot.SetSnapshot(); return(result.NumberOfRowsAffected); } }
internal static string ConstructUpdateQuery(this DirectModel model) { if (model.IntegerPrimary && !model.ID.HasValue) { throw new Exception("ID is not set, maybe this table was not loaded"); } model.OnBeforeUpdate(); string updateData = model.Snapshot.GetUpdateData(); if (string.IsNullOrEmpty(updateData)) { return(string.Empty); } // UPDATE MobilePaywall.core.A SET A=1 WHERE AID=1 string command = string.Format(DirectModelHelper.GetDatabase(model).QueryConstructUpdateQuery, model.GetTableName(), model.Snapshot.GetUpdateData(), model.GetIdNameValue(), (model.IntegerPrimary ? model.ID.Value.ToString() : string.Format("'{0}'", model.GetStringID()))); return(command); }
public static async Task <bool> DeleteAsync(this DirectDatabaseBase db, DirectModel model) { if (model.IntegerPrimary && !model.ID.HasValue) { throw new Exception("THIS model has not ID"); } string command = string.Format(DirectModelHelper.GetDatabase(model).QueryDelete, model.GetTableName(), model.GetIdNameValue(), (model.IntegerPrimary ? model.ID.Value.ToString() : string.Format("'{0}'", model.GetStringID()))); DirectExecuteResult result = await db.ExecuteAsync(command); if (result.IsSuccessfull) { model.ID = null; model.Snapshot.SetSnapshot(); return(true); } return(false); }