/// <summary>
        /// Gets a collection of order items that are associated with a subscription plan.
        /// </summary>
        /// <param name="orderId">The id of the order to get items for.</param>
        /// <returns>A collection of order items that are associated with a subscription plan.</returns>
        public static OrderItemCollection LoadSubscriptionItems(int orderId)
        {
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT " + OrderItem.GetColumnNames("OI"));
            selectQuery.Append(" FROM ac_OrderItems OI INNER JOIN ac_SubscriptionPlans SP ON OI.ProductId = SP.ProductId");
            selectQuery.Append(" WHERE OI.OrderId = @orderId");
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@orderId", System.Data.DbType.Int32, orderId);
            //EXECUTE THE COMMAND
            OrderItemCollection results = new OrderItemCollection();

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read())
                {
                    OrderItem orderItem = new OrderItem();
                    OrderItem.LoadDataReader(orderItem, dr);
                    results.Add(orderItem);
                }
                dr.Close();
            }
            return(results);
        }
Exemple #2
0
        /// <summary>
        /// Generate subscriptions for order items
        /// </summary>
        /// <param name="order">The order being created</param>
        /// <param name="orderItemSubscriptions">Generated subscriptions are returned in this parameter</param>
        internal static void GenerateOrderSubscriptions(Order order, Dictionary <int, Subscription[]> orderItemSubscriptions)
        {
            //GENERATE (BUT DO NOT ACTIVATE) SUBSCRIPTIONS
            //BUILD A LIST OF RECURRING SUBSCRIPTIONS GROUPED BY ORDER ITEM
            OrderItemCollection subscriptionItems = OrderItemDataSource.LoadSubscriptionItems(order.OrderId);

            if (subscriptionItems.Count > 0)
            {
                foreach (OrderItem orderItem in subscriptionItems)
                {
                    Subscription[] allSubs = orderItem.GenerateSubscriptions(false);
                    if ((allSubs != null) && (allSubs.Length > 0))
                    {
                        List <Subscription> recurringSubs = new List <Subscription>();
                        foreach (Subscription sub in allSubs)
                        {
                            if (sub.SubscriptionPlan.IsRecurring)
                            {
                                recurringSubs.Add(sub);
                            }
                        }
                        if (recurringSubs.Count > 0)
                        {
                            orderItemSubscriptions.Add(orderItem.OrderItemId, recurringSubs.ToArray());
                        }
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Gets a collection of all order items in this collection that belong to a particular shipment
        /// and sorts them.
        /// </summary>
        /// <param name="orderShipmentId">Id of the order shipment for which to get the order items</param>
        /// <returns>Sorted collection of order items</returns>
        public OrderItemCollection FilterByShipmentAndSort(int orderShipmentId)
        {
            OrderItemCollection newCollection = FilterByShipment(orderShipmentId);

            if (newCollection != null)
            {
                newCollection.Sort(new OrderItemComparer());
            }
            return(newCollection);
        }
Exemple #4
0
        /// <summary>
        /// Gets a collection of all order items in this collection that belong to a particular shipment.
        /// </summary>
        /// <param name="orderShipmentId">Id of the order shipment for which to get the order items</param>
        /// <returns>Collection of order items</returns>
        public OrderItemCollection FilterByShipment(int orderShipmentId)
        {
            OrderItemCollection newCollection = new OrderItemCollection();

            foreach (OrderItem item in this)
            {
                if (item.OrderShipmentId == orderShipmentId)
                {
                    newCollection.Add(item);
                }
            }
            return(newCollection);
        }
Exemple #5
0
        public static OrderItemCollection LoadForWrapStyle(Int32 wrapStyleId, 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(" " + OrderItem.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_OrderItems");
            selectQuery.Append(" WHERE WrapStyleId = @wrapStyleId");
            selectQuery.Append(" ORDER BY " + sortExpression);
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

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

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        OrderItem orderItem = new OrderItem();
                        OrderItem.LoadDataReader(orderItem, dr);
                        results.Add(orderItem);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
        public static OrderItemCollection LoadForOrderItemType(OrderItemType orderItemType, DateTime startDate, DateTime endDate, int maximumRows, int startRowIndex)
        {
            //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(" " + OrderItem.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_OrderItems");
            selectQuery.Append(" WHERE OrderItemTypeId = @orderItemType");
            selectQuery.Append(" AND OrderId IN ( SELECT OrderId From ac_Orders WHERE StoreId = @storeId");
            if (startDate > DateTime.MinValue)
            {
                //CONVERT DATE TO UTC
                startDate = LocaleHelper.FromLocalTime(startDate);
                selectQuery.Append(" AND OrderDate >= @startDate");
            }
            if (endDate > DateTime.MinValue)
            {
                //CONVERT DATE TO UTC
                endDate = LocaleHelper.FromLocalTime(endDate);
                selectQuery.Append(" AND OrderDate <= @endDate");
            }
            selectQuery.Append(")");
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@orderItemType", System.Data.DbType.Int32, orderItemType);
            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            if (startDate > DateTime.MinValue)
            {
                database.AddInParameter(selectCommand, "@startDate", System.Data.DbType.DateTime, startDate);
            }
            if (endDate > DateTime.MinValue)
            {
                database.AddInParameter(selectCommand, "@endDate", System.Data.DbType.DateTime, endDate);
            }
            //EXECUTE THE COMMAND
            OrderItemCollection results = new OrderItemCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        OrderItem orderItem = new OrderItem();
                        OrderItem.LoadDataReader(orderItem, dr);
                        results.Add(orderItem);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }