public static ProductAsset Load(Int32 productAssetId, bool useCache)
        {
            if (productAssetId == 0)
            {
                return(null);
            }
            ProductAsset productAsset = null;
            string       key          = "ProductAsset_" + productAssetId.ToString();

            if (useCache)
            {
                productAsset = ContextCache.GetObject(key) as ProductAsset;
                if (productAsset != null)
                {
                    return(productAsset);
                }
            }
            productAsset = new ProductAsset();
            if (productAsset.Load(productAssetId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, productAsset);
                }
                return(productAsset);
            }
            return(null);
        }
 /// <summary>
 /// Loads the given ProductAsset object from the given database data reader.
 /// </summary>
 /// <param name="productAsset">The ProductAsset object to load.</param>
 /// <param name="dr">The database data reader to read data from.</param>
 public static void LoadDataReader(ProductAsset productAsset, IDataReader dr)
 {
     //SET FIELDS FROM ROW DATA
     productAsset.ProductAssetId = dr.GetInt32(0);
     productAsset.ProductId      = dr.GetInt32(1);
     productAsset.AssetUrl       = dr.GetString(2);
     productAsset.OrderBy        = dr.GetInt16(3);
     productAsset.IsDirty        = false;
 }
        public static bool Delete(Int32 productAssetId)
        {
            ProductAsset productAsset = new ProductAsset();

            if (productAsset.Load(productAssetId))
            {
                return(productAsset.Delete());
            }
            return(false);
        }
        public static ProductAssetCollection LoadForProduct(Int32 productId, 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(" " + ProductAsset.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_ProductAssets");
            selectQuery.Append(" WHERE ProductId = @productId");
            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
            ProductAssetCollection results = new ProductAssetCollection();
            int thisIndex = 0;
            int rowCount  = 0;

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