Exemplo n.º 1
0
        /// <summary>
        /// Loads a Coupon object for the given coupon code
        /// </summary>
        /// <param name="couponCode">Coupon code for which to load the coupon</param>
        /// <returns>The Coupon object loaded</returns>
        public static Coupon LoadForCouponCode(string couponCode)
        {
            couponCode = couponCode.ToUpperInvariant();
            string key    = "Coupon_" + couponCode;
            Coupon coupon = ContextCache.GetObject(key) as Coupon;

            if (coupon != null)
            {
                return(coupon);
            }
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT CouponId");
            selectQuery.Append(" FROM ac_Coupons");
            selectQuery.Append(" WHERE CouponCode = @couponCode");
            selectQuery.Append(" AND StoreId = @storeId");
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@couponCode", System.Data.DbType.String, couponCode);
            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            int couponId = AlwaysConvert.ToInt(database.ExecuteScalar(selectCommand));

            if (couponId != 0)
            {
                coupon = CouponDataSource.Load(couponId);
                ContextCache.SetObject(key, coupon);
                return(coupon);
            }
            return(null);
        }
Exemplo n.º 2
0
 public static Coupon Load(Int32 couponId)
 {
     return(CouponDataSource.Load(couponId, true));
 }