public static async Task <int?> UpdateAsync(this DirectDatabaseBase db, DirectModel model) { if (!model.LongID.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("UPDATE {0}.{1}{2} SET {3} WHERE {4}={5};", db.DatabaseName, db.DatabaseSchemeString, model.GetTableName(), model.Snapshot.GetUpdateData(), model.GetIdNameValue(), model.LongID.Value); DirectExecuteResult result = await db.ExecuteAsync(command); if (!result.IsSuccessfull) { return(null); } else { model.OnAfterUpdate?.Invoke(); model.Snapshot.SetSnapshot(); return(result.NumberOfRowsAffected); } }
internal static string ConstructUpdateQuery(this DirectModel model) { if (!model.LongID.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 command = string.Format("UPDATE {0}.{1}{2} SET {3} WHERE {4}={5};", model.GetDatabase().DatabaseName, model.GetDatabase().DatabaseSchemeString, model.GetTableName(), model.Snapshot.GetUpdateData(), model.GetIdNameValue(), model.LongID.Value); return(command); }
public static async Task <bool> DeleteAsync(this DirectDatabaseBase db, DirectModel model) { if (!model.LongID.HasValue) { throw new Exception("THIS model has not ID"); } string command = string.Format("DELETE FROM {0}.{1}{2} WHERE {3}={4};", db.DatabaseName, db.DatabaseSchemeString, model.GetTableName(), model.GetIdNameValue(), model.LongID.Value); DirectExecuteResult result = await db.ExecuteAsync(command); if (result.IsSuccessfull) { model.LongID = null; model.Snapshot.SetSnapshot(); return(true); } return(false); }