public static ProductCustomField Load(Int32 productFieldId, bool useCache)
        {
            if (productFieldId == 0)
            {
                return(null);
            }
            ProductCustomField productCustomField = null;
            string             key = "ProductCustomField_" + productFieldId.ToString();

            if (useCache)
            {
                productCustomField = ContextCache.GetObject(key) as ProductCustomField;
                if (productCustomField != null)
                {
                    return(productCustomField);
                }
            }
            productCustomField = new ProductCustomField();
            if (productCustomField.Load(productFieldId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, productCustomField);
                }
                return(productCustomField);
            }
            return(null);
        }
        public static bool Delete(Int32 productFieldId)
        {
            ProductCustomField productCustomField = new ProductCustomField();

            if (productCustomField.Load(productFieldId))
            {
                return(productCustomField.Delete());
            }
            return(false);
        }
Exemple #3
0
 /// <summary>
 /// Loads the given ProductCustomField object from the given database data reader.
 /// </summary>
 /// <param name="productCustomField">The ProductCustomField object to load.</param>
 /// <param name="dr">The database data reader to read data from.</param>
 public static void LoadDataReader(ProductCustomField productCustomField, IDataReader dr)
 {
     //SET FIELDS FROM ROW DATA
     productCustomField.ProductFieldId = dr.GetInt32(0);
     productCustomField.ProductId      = dr.GetInt32(1);
     productCustomField.IsUserDefined  = dr.GetBoolean(2);
     productCustomField.IsVisible      = dr.GetBoolean(3);
     productCustomField.FieldName      = dr.GetString(4);
     productCustomField.FieldValue     = NullableData.GetString(dr, 5);
     productCustomField.IsDirty        = false;
 }
        public static ProductCustomFieldCollection LoadForProduct(Int32 productId, 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(" " + ProductCustomField.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_ProductCustomFields");
            selectQuery.Append(" WHERE ProductId = @productId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

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

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