private static RedirectCollection LoadRedirects(bool dynamic, int maximumRows, int startRowIndex, string sortExpression) { int storeId = Token.Instance.StoreId; //DEFAULT SORT EXPRESSION if (string.IsNullOrEmpty(sortExpression)) { sortExpression = "OrderBy"; } //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT"); if (maximumRows > 0) { selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString()); } selectQuery.Append(" " + Redirect.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_Redirects"); selectQuery.Append(" WHERE StoreId = @storeId"); selectQuery.Append(" AND UseRegEx = @useRegEx"); selectQuery.Append(" ORDER BY " + sortExpression); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, storeId); database.AddInParameter(selectCommand, "@useRegEx", System.Data.DbType.Boolean, dynamic); //EXECUTE THE COMMAND RedirectCollection results = new RedirectCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { Redirect redirect = new Redirect(); Redirect.LoadDataReader(redirect, dr); results.Add(redirect); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
public static RedirectCollection LoadForCriteria(string sqlCriteria, int maximumRows, int startRowIndex, string sortExpression) { //DEFAULT SORT EXPRESSION if (string.IsNullOrEmpty(sortExpression)) { sortExpression = "OrderBy"; } //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT"); if (maximumRows > 0) { selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString()); } selectQuery.Append(" " + Redirect.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_Redirects"); string whereClause = string.IsNullOrEmpty(sqlCriteria) ? string.Empty : " WHERE " + sqlCriteria; selectQuery.Append(whereClause); selectQuery.Append(" ORDER BY " + sortExpression); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); //EXECUTE THE COMMAND RedirectCollection results = new RedirectCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { Redirect redirect = new Redirect(); Redirect.LoadDataReader(redirect, dr); results.Add(redirect); rowCount++; } thisIndex++; } dr.Close(); } return(results); }