public int Update <T>(RepositoryRecord <T> item, string userName) where T : RepositoryRecord <T>, new() { if (userName == null) { throw new ArgumentNullException("userName"); } int result = 0; if (item.IsDirty) { QueryCommand cmd = ActiveHelper <T> .GetUpdateCommand(item, userName); result = DataService.ExecuteQuery(cmd); } item.DirtyColumns.Clear(); item.MarkOld(); item.MarkClean(); return(result); }
public void Delete <T>(string columnName, object columnValue) where T : RepositoryRecord <T>, new() { T item = new T(); TableSchema.Table tbl = item.GetSchema(); if (tbl.GetColumn(ReservedColumnName.DELETED) != null) { //create an update command new Update(tbl).Set(ReservedColumnName.DELETED).EqualTo(true).Where(columnName).IsEqualTo(columnValue).Execute(); } else if (tbl.GetColumn(ReservedColumnName.IS_DELETED) != null) { new Update(tbl).Set(ReservedColumnName.IS_DELETED).EqualTo(true).Where(columnName).IsEqualTo(columnValue).Execute(); } else { QueryCommand del = ActiveHelper <T> .GetDeleteCommand(columnName, columnValue); DataService.ExecuteQuery(del); } }
public int Insert <T>(RepositoryRecord <T> item, string userName) where T : RepositoryRecord <T>, new() { if (userName == null) { throw new ArgumentNullException("userName"); } int result = 0; QueryCommand cmd = ActiveHelper <T> .GetInsertCommand(item, userName); TableSchema.Table schema = item.GetSchema(); if (schema.PrimaryKey != null) { if (schema.PrimaryKey.AutoIncrement || schema.PrimaryKey.DataType == DbType.Guid) { object qResult = DataService.ExecuteScalar(cmd); item.SetColumnValue(schema.PrimaryKey.ColumnName, qResult); if (qResult != null) { int.TryParse(qResult.ToString(), out result); } } else { result = DataService.ExecuteQuery(cmd); } } else { result = DataService.ExecuteQuery(cmd); } item.DirtyColumns.Clear(); item.MarkOld(); item.MarkClean(); return(result); }
/// <summary> /// Gets the select command used to retrieve the AbstractRecord object. /// </summary> /// <returns></returns> public QueryCommand GetSelectCommand() { return(ActiveHelper <T> .GetSelectCommand(this)); }
/// <summary> /// Returns a DELETE QueryCommand object to delete the records with /// matching passed column/value criteria /// </summary> /// <param name="columnName">Name of the column to match</param> /// <param name="oValue">Value of column to match</param> /// <returns></returns> public static QueryCommand GetDeleteCommand(string columnName, object oValue) { return(ActiveHelper <T> .GetDeleteCommand(columnName, oValue)); }
/// <summary> /// Returns a DELETE QueryCommand object to delete the record with /// the primary key value matching the passed value /// </summary> /// <param name="keyID">The primary key record value to match for the delete</param> /// <returns></returns> public static QueryCommand GetDeleteCommand(object keyID) { return(ActiveHelper <T> .GetDeleteCommand(keyID)); }
/// <summary> /// Returns a UPDATE QueryCommand object used to generate SQL. /// </summary> /// <param name="userName">An optional username to be used if audit fields are present</param> /// <returns></returns> public QueryCommand GetUpdateCommand(string userName) { return(ActiveHelper <T> .GetUpdateCommand(this, userName)); }
/// <summary> /// Deletes the record in the table, even if it contains Deleted or IsDeleted flag columns /// </summary> /// <param name="columnName">The name of the column that whose value will be evaluated for deletion</param> /// <param name="oValue">The value that will be compared against columnName to determine deletion</param> /// <returns>Number of rows affected by the operation</returns> private static int DestroyByParameter(string columnName, object oValue) { return(ActiveHelper <T> .DestroyByParameter(columnName, oValue)); }
/// <summary> /// Deletes the record in the table, even if it contains Deleted or IsDeleted flag columns /// </summary> /// <param name="keyID">The key ID.</param> /// <returns>Number of rows affected by the operation</returns> public static int Destroy(object keyID) { return(ActiveHelper <T> .DestroyByParameter(BaseSchema.PrimaryKey.ColumnName, keyID)); }
/// <summary> /// If the record contains Deleted or IsDeleted flag columns, sets them to true. If not, invokes Destroy() /// </summary> /// <param name="columnName">The name of the column that whose value will be evaluated for deletion</param> /// <param name="oValue">The value that will be compared against columnName to determine deletion</param> /// <param name="userName">The userName that the record will be updated with. Only relevant if the record contains Deleted or IsDeleted properties</param> /// <returns>Number of rows affected by the operation</returns> private static int DeleteByParameter(string columnName, object oValue, string userName) { return(ActiveHelper <T> .Delete(columnName, oValue, userName)); }
/// <summary> /// Deletes the specified column name. /// </summary> /// <param name="columnName">Name of the column.</param> /// <param name="oValue">The o value.</param> /// <param name="userName">Name of the user.</param> /// <returns></returns> public static int Delete(string columnName, object oValue, string userName) { return(ActiveHelper <ItemType> .Delete(columnName, oValue, userName)); }
public static void Destroy(string columnName, object param) { ActiveHelper <ItemType> .DestroyByParameter(columnName, param); }
public static void Delete(string columnName, object param) { new ItemType(); ActiveHelper <ItemType> .Delete(columnName, param, String.Empty); }
public static void Delete(object keyID) { ItemType item = new ItemType(); ActiveHelper <ItemType> .Delete(item.GetSchema().PrimaryKey.ColumnName, keyID, String.Empty); }
/// <summary> /// Gets the update command. /// </summary> /// <param name="item">The item.</param> /// <param name="userName">Name of the user.</param> /// <returns></returns> public static QueryCommand GetUpdateCommand(ItemType item, string userName) { return(ActiveHelper <ItemType> .GetUpdateCommand(item, userName)); }