/// <summary>
 /// Loads the given CategoryParent object from the given database data reader.
 /// </summary>
 /// <param name="categoryParent">The CategoryParent object to load.</param>
 /// <param name="dr">The database data reader to read data from.</param>
 public static void LoadDataReader(CategoryParent categoryParent, IDataReader dr)
 {
     //SET FIELDS FROM ROW DATA
     categoryParent.CategoryId   = dr.GetInt32(0);
     categoryParent.ParentId     = dr.GetInt32(1);
     categoryParent.ParentLevel  = NullableData.GetByte(dr, 2);
     categoryParent.ParentNumber = NullableData.GetByte(dr, 3);
     categoryParent.IsDirty      = false;
 }
        public static CategoryParent Load(Int32 categoryId, Int32 parentId)
        {
            CategoryParent categoryParent = new CategoryParent();

            if (categoryParent.Load(categoryId, parentId))
            {
                return(categoryParent);
            }
            return(null);
        }
        public static bool Delete(Int32 categoryId, Int32 parentId)
        {
            CategoryParent categoryParent = new CategoryParent();

            if (categoryParent.Load(categoryId, parentId))
            {
                return(categoryParent.Delete());
            }
            return(false);
        }
        public static CategoryParentCollection LoadForCategory(Int32 categoryId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //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(" " + CategoryParent.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_CategoryParents");
            selectQuery.Append(" WHERE CategoryId = @categoryId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@categoryId", System.Data.DbType.Int32, categoryId);
            //EXECUTE THE COMMAND
            CategoryParentCollection results = new CategoryParentCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        CategoryParent categoryParent = new CategoryParent();
                        CategoryParent.LoadDataReader(categoryParent, dr);
                        results.Add(categoryParent);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
 public static SaveResult Insert(CategoryParent categoryParent)
 {
     return(categoryParent.Save());
 }
 public static SaveResult Update(CategoryParent categoryParent)
 {
     return(categoryParent.Save());
 }
 public static bool Delete(CategoryParent categoryParent)
 {
     return(categoryParent.Delete());
 }