/// <summary>
 /// Loads the given OrderCoupon object from the given database data reader.
 /// </summary>
 /// <param name="orderCoupon">The OrderCoupon object to load.</param>
 /// <param name="dr">The database data reader to read data from.</param>
 public static void LoadDataReader(OrderCoupon orderCoupon, IDataReader dr)
 {
     //SET FIELDS FROM ROW DATA
     orderCoupon.OrderId    = dr.GetInt32(0);
     orderCoupon.CouponCode = dr.GetString(1);
     orderCoupon.IsDirty    = false;
 }
Esempio n. 2
0
        public static OrderCoupon Load(Int32 orderId, String couponCode)
        {
            OrderCoupon orderCoupon = new OrderCoupon();

            if (orderCoupon.Load(orderId, couponCode))
            {
                return(orderCoupon);
            }
            return(null);
        }
Esempio n. 3
0
        public static bool Delete(Int32 orderId, String couponCode)
        {
            OrderCoupon orderCoupon = new OrderCoupon();

            if (orderCoupon.Load(orderId, couponCode))
            {
                return(orderCoupon.Delete());
            }
            return(false);
        }
Esempio n. 4
0
 /// <summary>
 /// Transcribes coupons associated with the basket into the new order
 /// </summary>
 /// <param name="basket">The basket checking out</param>
 /// <param name="order">The order being created</param>
 /// <remarks>This method does not modify the basket object</remarks>
 internal static void GenerateOrderCoupons(Basket basket, Order order)
 {
     foreach (BasketCoupon bc in basket.BasketCoupons)
     {
         //THIS MAKES SURE THE COUPON IS STILL VALID IN THE DATABASE?
         //TODO: CHECK BASKETCOUPON.DELETE METHOD FOR DB INTEGRITY RULES
         if (bc.Coupon != null)
         {
             OrderCoupon oc = new OrderCoupon();
             oc.OrderId    = order.OrderId;
             oc.CouponCode = bc.Coupon.CouponCode;
             oc.Save();
             order.Coupons.Add(oc);
         }
     }
 }
Esempio n. 5
0
        public static OrderCouponCollection LoadForOrder(Int32 orderId, 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(" " + OrderCoupon.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_OrderCoupons");
            selectQuery.Append(" WHERE OrderId = @orderId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

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

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