public void HavingWithComplexExpression()
        {
            OrderItemCollection coll = new OrderItemCollection();

            coll.es.Connection.Name = "ForeignKeyTest";

            OrderItemQuery q = new OrderItemQuery();

            q.Select(q.OrderID, (q.Quantity * q.UnitPrice).Sum().As("TotalPrice"));
            q.Where(q.Discount.IsNull());
            q.GroupBy(q.OrderID);
            q.Having((q.Quantity * q.UnitPrice).Sum() > 500);

            switch (coll.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.SqlServerCeProvider":
            case "EntitySpaces.SqlServerCe4Provider":
            case "EntitySpaces.VistaDBProvider":
            case "EntitySpaces.VistaDB4Provider":
                q.OrderBy("<TotalPrice>", esOrderByDirection.Descending);
                break;

            default:
                q.OrderBy((q.Quantity * q.UnitPrice).Sum().Descending);
                break;
            }

            Assert.IsTrue(coll.Load(q), "Load");
            Assert.AreEqual(2, coll.Count, "Count");

            decimal price = Convert.ToDecimal(coll[0].GetColumn("TotalPrice"));

            Assert.AreEqual(1940.0M, price, "GetColumn");
        }
Exemple #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //currentOrder = OrderController.GetCurrentOrder();

        OrderItemCollection orderItemCollection = OrderController.GetCartItems();

        foreach (OrderItem currentItem in orderItemCollection)
        {
            if ((currentItem.ImageFile == null) || (currentItem.ImageFile.Length == 0))
            {
                currentItem.ImageFile = "images/ProductImages/no_image_available_small.gif";
            }
        }

        rptBasket.DataSource = orderItemCollection;
        rptBasket.DataBind();

        decimal dTotal = 0;

        foreach (OrderItem item in orderItemCollection)
        {
            dTotal += item.LineTotal;
        }

        lblSubtotal.Text = dTotal.ToString("c");
    }
        public void OneModLiteral()
        {
            OrderItemCollection collection = new OrderItemCollection();

            collection.es.Connection.Name = "ForeignKeyTest";


            switch (collection.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.MSAccessProvider":
                Assert.Ignore("Not supported");
                break;

            default:

                OrderItemQuery oiq = new OrderItemQuery("oiq");

                oiq.Select(oiq.OrderID, oiq.ProductID,
                           (oiq.Quantity % 2).As("SomeInteger"));
                oiq.OrderBy(oiq.OrderID, esOrderByDirection.Ascending);
                oiq.OrderBy(oiq.ProductID, esOrderByDirection.Ascending);

                Assert.IsTrue(collection.Load(oiq));

                decimal someInt = Convert.ToInt32(collection[0].GetColumn("SomeInteger"));
                Assert.AreEqual(1, someInt);
                break;
            }
        }
        public void Correlated()
        {
            OrderItemCollection collection = new OrderItemCollection();

            collection.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(collection.es.Connection);

            OrderItemQuery oiq = new OrderItemQuery("oi");
            ProductQuery   pq  = new ProductQuery("p");

            // oiq.ProductID in the inner Select is pulled from
            // the outer Select, making a correlated SubQuery.
            oiq.Select(
                oiq.OrderID,
                (oiq.Quantity * oiq.UnitPrice).Sum().As("Total")
                );
            oiq.Where(oiq.ProductID
                      .In(
                          pq.Select(pq.ProductID)
                          .Where(oiq.ProductID == pq.ProductID)
                          )
                      );
            oiq.GroupBy(oiq.OrderID);

            Assert.IsTrue(collection.Load(oiq));
            Assert.AreEqual(5, collection.Count);
        }
        public void CombineFilteredOriginalAndCombine()
        {
            // Load a collection and apply a filter.
            OrderItemCollection coll = new OrderItemCollection();

            coll.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll.es.Connection);

            coll.LoadAll();
            Assert.AreEqual(15, coll.Count);
            coll.Filter = coll.AsQueryable().Where(f => f.ProductID == 1);
            Assert.AreEqual(4, coll.Count);

            // Load a second collection and apply a different filter.
            OrderItemCollection coll2 = new OrderItemCollection();

            coll2.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll2.es.Connection);

            coll2.LoadAll();
            Assert.AreEqual(15, coll2.Count);
            coll2.Filter = coll2.AsQueryable().Where(f => f.ProductID == 2);
            Assert.AreEqual(3, coll2.Count);

            // Add only the 3 filtered rows from coll2
            // to all 15 rows in coll1.
            // The filter for coll1 still applies.
            // None of the items from coll2 appear,
            // until the filter is removed from coll1.
            coll.Combine(coll2);
            Assert.AreEqual(4, coll.Count);
            coll.Filter = null;
            Assert.AreEqual(18, coll.Count);
        }
        public void CombineFilteredOriginal()
        {
            // Load a collection and apply a filter
            OrderItemCollection coll = new OrderItemCollection();

            coll.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll.es.Connection);

            coll.LoadAll();
            Assert.AreEqual(15, coll.Count);
            coll.Filter = coll.AsQueryable().Where(f => f.ProductID == 1);
            Assert.AreEqual(4, coll.Count);

            // Load a second collection
            OrderItemCollection coll2 = new OrderItemCollection();

            coll2.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll2.es.Connection);

            coll2.LoadAll();
            Assert.AreEqual(15, coll2.Count);

            // Combine the 15 rows from the second collection
            // to the 15 rows from the first collection.
            // Since the first collection still has a filter,
            // only 8 rows are counted (4 from the first and 4 from the second).
            coll.Combine(coll2);
            Assert.AreEqual(8, coll.Count);

            // Remove the filter to count all 30 rows.
            coll.Filter = null;
            Assert.AreEqual(30, coll.Count);
        }
 public OrderItemCollection FetchAll()
 {
     OrderItemCollection coll = new OrderItemCollection();
     Query qry = new Query(OrderItem.Schema);
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
Exemple #8
0
    protected void DetermineBasketContents(out int nMaleFullQty,
                                           out int nMaleDiscountQty,
                                           out int nFemaleFullQty,
                                           out int nFemaleDiscountQty)
    {
        nMaleFullQty       = 0;
        nMaleDiscountQty   = 0;
        nFemaleFullQty     = 0;
        nFemaleDiscountQty = 0;

        // Calculate total, male, female qty
        OrderItemCollection orderItemCollection = OrderController.GetCartItems();

        foreach (OrderItem currentItem in orderItemCollection)
        {
            if ("LRM1" == currentItem.Sku)
            {
                nMaleFullQty += currentItem.Quantity;
            }
            if ("LRMCC1" == currentItem.Sku)
            {
                nMaleDiscountQty += currentItem.Quantity;
            }
            if ("LRW1" == currentItem.Sku)
            {
                nFemaleFullQty += currentItem.Quantity;
            }
            if ("LRWCC1" == currentItem.Sku)
            {
                nFemaleDiscountQty += currentItem.Quantity;
            }
        }
    }
Exemple #9
0
        public void TestCollectionDeleteAll()
        {
            int     prdId = -1;
            Product prd   = new Product();

            prd.es.Connection.Name = "ForeignKeyTest";

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    prd.ProductName  = "UnitTest";
                    prd.UnitPrice    = 1;
                    prd.Discontinued = false;
                    for (int i = 0; i < 3; i++)
                    {
                        OrderItem oi = prd.OrderItemCollectionByProductID.AddNew();
                        oi.OrderID   = i + 1;
                        oi.UnitPrice = prd.UnitPrice;
                        oi.Quantity  = Convert.ToInt16(i);
                        oi.Discount  = 0;
                    }
                    prd.Save();
                    prdId = prd.ProductID.Value;

                    // Test
                    ProductCollection collection = new ProductCollection();
                    collection.es.Connection.Name = "ForeignKeyTest";

                    Assert.IsTrue(collection.LoadAll());
                    Product entity = collection.FindByPrimaryKey(prdId);
                    Assert.AreEqual(3, entity.OrderItemCollectionByProductID.Count);
                    entity.OrderItemCollectionByProductID.MarkAllAsDeleted();
                    entity.MarkAsDeleted();
                    collection.Save();

                    prd = new Product();
                    prd.es.Connection.Name = "ForeignKeyTest";
                    Assert.IsFalse(prd.LoadByPrimaryKey(prdId));

                    OrderItemCollection oic = new OrderItemCollection();
                    oic.es.Connection.Name = "ForeignKeyTest";
                    oic.Query.Where(oic.Query.ProductID == prdId);
                    Assert.IsFalse(oic.Query.Load());
                }
            }
            finally
            {
                prd = new Product();
                prd.es.Connection.Name = "ForeignKeyTest";

                if (prd.LoadByPrimaryKey(prdId))
                {
                    prd.OrderItemCollectionByProductID.MarkAllAsDeleted();
                    prd.MarkAsDeleted();
                    prd.Save();
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Calculates and applies taxes for the given order
        /// </summary>
        /// <param name="basket">The order to calculate taxes on.</param>
        /// <returns>The total amount of tax applied.</returns>
        /// <remarks>Any pre-existing tax line items must be removed from the order before the calculation.</remarks>
        public override LSDecimal Recalculate(Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            // CREATE THE DOR GATEWAY INSTANCE
            DorGateway gateway = new DorGateway(order, this.TaxName, this.UseDebugMode);

            // BUILD A DICTIONARY OF TAXABLE TOTALS BY SHIPMENT
            Dictionary <int, decimal> shipmentTotals = new Dictionary <int, decimal>();

            // LOOP ITEMS IN BASKET TO CALCULATE TAX
            OrderItemCollection newTaxItems = new OrderItemCollection();

            foreach (OrderItem item in order.Items)
            {
                // SEE IF ITEM HAS A TAX CODE THAT APPLIES
                if (item.TaxCodeId > 0 && this.TaxCodes.Contains(item.TaxCodeId))
                {
                    if (shipmentTotals.ContainsKey(item.OrderShipmentId))
                    {
                        shipmentTotals[item.OrderShipmentId] += (decimal)item.ExtendedPrice;
                    }
                    else
                    {
                        shipmentTotals[item.OrderShipmentId] = (decimal)item.ExtendedPrice;
                    }
                }
            }

            // LOOP TAXABLE SHIPMENT TOTALS
            LSDecimal totalTax = 0;

            foreach (int shipmentId in shipmentTotals.Keys)
            {
                // SEE IF THERE IS A TAXINFO INSTANCE FOR THIS ITEM
                TaxInfo taxInfo = gateway.GetTaxInfo(shipmentId);
                if (taxInfo != null)
                {
                    // A TAXINFO STRUCTURE EXISTS, SO CREATE TAX ITEM AND ADD TO BASKET
                    OrderItem taxItem = TaxUtility.GenerateOrderItem(order.OrderId, shipmentId, shipmentTotals[shipmentId], taxInfo);
                    totalTax += taxItem.ExtendedPrice;
                    order.Items.Add(taxItem);
                }
            }

            // SAVE ORDER
            order.Items.Save();

            // return total tax added to basekt
            return(newTaxItems.TotalPrice());
        }
        public void HavingWithSimpleExpression()
        {
            OrderItemCollection coll = new OrderItemCollection();

            coll.es.Connection.Name = "ForeignKeyTest";

            OrderItemQuery q = new OrderItemQuery();

            //q.es2.Connection.Name = "ForeignKeyTest";

            q.Select(q.OrderID, q.Quantity.Sum().As("TotalQty"));
            q.Where(q.Discount.IsNull());
            q.GroupBy(q.OrderID);

            switch (coll.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.SqlServerCeProvider":
            case "EntitySpaces.SqlServerCe4Provider":
            case "EntitySpaces.VistaDBProvider":
            case "EntitySpaces.VistaDB4Provider":
                q.Having(q.Quantity.Sum() > 100);
                q.OrderBy("<TotalQty>", esOrderByDirection.Descending);
                break;

            case "EntitySpaces.SQLiteProvider":
                q.Having((q.Quantity * 1).Sum() > 100);
                q.OrderBy(q.Quantity.Sum().Descending);
                break;

            default:
                q.Having(q.Quantity.Sum() > 100);
                q.OrderBy(q.Quantity.Sum().Descending);
                break;
            }

            Assert.IsTrue(coll.Load(q), "Load");
            Assert.AreEqual(3, coll.Count, "Count");

            int qty = Convert.ToInt32(coll[0].GetColumn("TotalQty"));

            Assert.AreEqual(240, qty, "GetColumn");
        }
        public void OneWhereSubtract()
        {
            OrderItemCollection collection = new OrderItemCollection();

            collection.es.Connection.Name = "ForeignKeyTest";

            OrderItemQuery oiq = new OrderItemQuery("oiq");

            oiq.Select(oiq.OrderID, oiq.ProductID,
                       (oiq.UnitPrice - oiq.Discount).As("SomeDecimal"));
            oiq.Where(oiq.UnitPrice - oiq.Discount < .2);
            oiq.OrderBy(oiq.OrderID, esOrderByDirection.Ascending);
            oiq.OrderBy(oiq.ProductID, esOrderByDirection.Ascending);

            Assert.IsTrue(collection.Load(oiq));

            decimal someDec = Convert.ToDecimal(collection[0].GetColumn("SomeDecimal"));

            Assert.AreEqual(Convert.ToDecimal("0.10"), Math.Round(someDec, 2));
        }
        public void CombineCollections()
        {
            OrderItemCollection coll = new OrderItemCollection();

            coll.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll.es.Connection);

            coll.LoadAll();
            Assert.AreEqual(15, coll.Count);

            OrderItemCollection coll2 = new OrderItemCollection();

            coll2.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll2.es.Connection);

            coll2.LoadAll();
            Assert.AreEqual(15, coll2.Count);

            coll.Combine(coll2);
            Assert.AreEqual(30, coll.Count);
        }
Exemple #14
0
        public void SimpleSyntaxCheck()
        {
            OrderItemQuery oq = new OrderItemQuery();

            oq.es2.Connection.Name = "ForeignKeyTest";

            oq.Select
            (
                oq.UnitPrice
                .Case()
                .When(oq.Quantity < 50).Then(oq.UnitPrice)
                .When(oq.Quantity >= 50 && oq.Quantity < 70).Then(oq.UnitPrice * .90)
                .When(oq.Quantity >= 70 && oq.Quantity < 99).Then(oq.UnitPrice * .80)
                .Else(oq.UnitPrice * .70)
                .End()
            );

            OrderItemCollection coll = new OrderItemCollection();

            coll.es.Connection.Name = "ForeignKeyTest";
            coll.Load(oq);
        }
        public void CombineBuildOriginal()
        {
            // Start with an empty collection
            OrderItemCollection coll = new OrderItemCollection();

            coll.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll.es.Connection);

            Assert.AreEqual(0, coll.Count);

            OrderItemCollection coll2 = new OrderItemCollection();

            coll2.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll2.es.Connection);

            coll2.LoadAll();
            Assert.AreEqual(15, coll2.Count);
            coll2.Filter = coll2.AsQueryable().Where(f => f.ProductID == 1);
            Assert.AreEqual(4, coll2.Count);

            // Add only the 4 filtered rows for coll2
            coll.Combine(coll2);
            Assert.AreEqual(4, coll.Count);

            OrderItemCollection coll3 = new OrderItemCollection();

            coll3.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll3.es.Connection);

            coll3.LoadAll();
            Assert.AreEqual(15, coll3.Count);
            coll3.Filter = coll3.AsQueryable().Where(f => f.ProductID == 2);
            Assert.AreEqual(3, coll3.Count);

            // Add only the 3 filtered rows for coll3
            // coll1 now has all 7 rows
            coll.Combine(coll3);
            Assert.AreEqual(7, coll.Count);
        }
Exemple #16
0
    void BindBasket()
    {
        int orderID = OrderController.GetCartOrderID();

        //Order currentOrder = null;
        if (orderID != 0)
        {
            currentOrder = OrderController.GetOrder(orderID);

            //Load up the no_image_available.gif image in the event there is no ImageFile
            OrderItemCollection orderItemCollection = currentOrder.Items;
            foreach (OrderItem currentItem in orderItemCollection)
            {
                if ((currentItem.ImageFile == null) || (currentItem.ImageFile.Length == 0))
                {
                    currentItem.ImageFile = "images/ProductImages/no_image_available.gif";
                }
            }
            //Bind it up
            rptBasket.DataSource = currentOrder.Items;
            rptBasket.DataBind();

            if (rptBasket.Items.Count == 0)
            {
                HideBits();
            }

            lblSubtotal.Text = currentOrder.CalculateSubTotal().ToString("c");
            if (!SiteConfig.UsePayPalExpressCheckout)
            {
                pnlExpressCheckout.Visible = false;
            }
        }
        else
        {
            HideBits();
        }
    }
        public void CombineFilteredCombine()
        {
            OrderItemCollection coll = new OrderItemCollection();

            coll.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll.es.Connection);

            coll.LoadAll();
            Assert.AreEqual(15, coll.Count);

            OrderItemCollection coll2 = new OrderItemCollection();

            coll2.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll2.es.Connection);

            coll2.LoadAll();
            Assert.AreEqual(15, coll2.Count);
            coll2.Filter = coll.AsQueryable().Where(f => f.ProductID == 1);
            Assert.AreEqual(4, coll2.Count);

            coll.Combine(coll2);
            Assert.AreEqual(19, coll.Count);
        }
        public void CombineQueriedCollections()
        {
            OrderItemCollection coll = new OrderItemCollection();

            coll.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll.es.Connection);

            coll.Query.Where(coll.Query.ProductID == 1);
            coll.Query.Load();
            Assert.AreEqual(4, coll.Count);

            OrderItemCollection coll2 = new OrderItemCollection();

            coll2.es.Connection.ConnectionString =
                UnitTestBase.GetFktString(coll2.es.Connection);

            coll2.Query.Where(coll2.Query.ProductID == 2);
            coll2.Query.Load();
            Assert.AreEqual(3, coll2.Count);

            coll.Combine(coll2);
            Assert.AreEqual(7, coll.Count);
        }
Exemple #19
0
    public static void SetDiscount()
    {
        //int nTotalQuantity = 0;

        /**
         * calculate total qty, maleqty, femaleqty;
         *
         **/

        // New prices 09/13/09:First tub3 19.99, all additional tubes 9.99

        /*****************************************
         * if 2 or more items
         *      if nMaleQty > 0
         *          put first Male in using current ID (LRM1)
         *          bAlreadyChargedFullPrice = true;*
         *          nMaleQty--;
         *
         *          while(0 != nMaleQty)
         *              add next item to cart as a new ID (LRMCC1, LRWCC1)
         *              nMaleQty--;
         *
         *      if nFemaleQty > 0
         *          if (!bAlreadyChargeFullPrice)
         *                  put first female in using current ID (LRW1)
         *                  bAlreadyChargedFullPrice = true;*
         *                  nFemaleQty--;
         *
         *          while(0 != nFemaleQty)
         *              add next item to cart as a new ID (LRMCC1, LRWCC1)
         *              nFemaleQty--;
         *      if nFreeBottle
         *          add RubLov Massage Gel into cart (DFDF).
         *
         ****************************************/
        OrderItemCollection orderItemCollection = OrderController.GetCartItems();
        Order currentOrder   = OrderController.GetCurrentOrder();
        int   nTotalQuantity = 0;

        foreach (OrderItem currentItem in orderItemCollection)
        {
            // don't count the free ones when calculating price. KPL 1/6/08
            if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
            {
                nTotalQuantity += currentItem.Quantity;
            }
        }

        // If total quantity of items is < 2, (ie, ==1), reset price to original, 19.99
        if (nTotalQuantity < 2)
        {
            // don't count the free ones. KPL 1/6/08
            foreach (OrderItem currentItem in orderItemCollection)
            {
                if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
                {
                    currentItem.PricePaid = currentItem.OriginalPrice;
                    currentItem.Save(Utility.GetUserName());
                }
            }
            // Add a Column to Order Table to save the collection as Xml to show it later !!!
            //currentOrder.DiscountDisplay = ddc.ToXml();
            currentOrder.Save(Utility.GetUserName());
            return;
        }

        // If total quantity of items is 2 or more, set first to 19.99, rest to 9.99
        if (nTotalQuantity >= 2)
        {
            // set price of 1st item to 19.99
            OrderItemCollection items = OrderController.GetCartItems();
            OrderItem           item  = items[0];

            item.PricePaid = item.OriginalPrice;
            item.Save(Utility.GetUserName());

            int nCount = items.Count;

            // set price of rest of items to 9.99
            for (int nIndex = 1; nIndex < nCount; nIndex++)
            {
                item           = items[nIndex];
                item.PricePaid = item.OriginalPrice - 10;
                item.Save(Utility.GetUserName());
            }
        }


        // If total quantity of items is 2 or more, set first to 19.99, rest to 9.99
        if (nTotalQuantity >= 2)
        {
            foreach (OrderItem currentItem in orderItemCollection)
            {
                // if it's a free product, ignore. KPL 01/06/08
                if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
                {
                    currentItem.PricePaid = currentItem.OriginalPrice - 2;
                    currentItem.Save(Utility.GetUserName());
                }
            }
            // Add a Column to Order Table to save the collection as Xml to show it later !!!
            //currentOrder.DiscountDisplay = ddc.ToXml();
            currentOrder.Save(Utility.GetUserName());
            return;
        }

        // If total quantity of items is 2, set each to 17.95
        if (2 == nTotalQuantity)
        {
            foreach (OrderItem currentItem in orderItemCollection)
            {
                if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
                {
                    currentItem.PricePaid = currentItem.OriginalPrice - 2;
                    currentItem.Save(Utility.GetUserName());
                }
            }
            // Add a Column to Order Table to save the collection as Xml to show it later !!!
            //currentOrder.DiscountDisplay = ddc.ToXml();
            currentOrder.Save(Utility.GetUserName());
            return;
        }

        /************ 09/13/09 KPL Commented out due to new price changes
         *      OrderItemCollection orderItemCollection = OrderController.GetCartItems();
         *      Order currentOrder = OrderController.GetCurrentOrder();
         *      int nTotalQuantity = 0;
         *
         *      foreach (OrderItem currentItem in orderItemCollection)
         *      {
         *          // don't count the free ones when calculating price. KPL 1/6/08
         *          if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
         *              nTotalQuantity += currentItem.Quantity;
         *      }
         *
         *      // If total quantity of items is < 2, reset price to original.
         *      if (nTotalQuantity < 2)
         *      {
         *          // don't count the free ones. KPL 1/6/08
         *          foreach (OrderItem currentItem in orderItemCollection)
         *          {
         *              if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
         *              {
         *                  currentItem.PricePaid = currentItem.OriginalPrice;
         *                  currentItem.Save(Utility.GetUserName());
         *              }
         *          }
         *          // Add a Column to Order Table to save the collection as Xml to show it later !!!
         *          //currentOrder.DiscountDisplay = ddc.ToXml();
         *          currentOrder.Save(Utility.GetUserName());
         *          return;
         *      }
         *
         *      // If total quantity of items is 3 or more, set each to 17.99
         *      if (nTotalQuantity >= 3)
         *      {
         *          foreach (OrderItem currentItem in orderItemCollection)
         *          {
         *              // if it's a free product, ignore. KPL 01/06/08
         *              if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
         *              {
         *                  currentItem.PricePaid = currentItem.OriginalPrice - 2;
         *                  currentItem.Save(Utility.GetUserName());
         *              }
         *          }
         *          // Add a Column to Order Table to save the collection as Xml to show it later !!!
         *          //currentOrder.DiscountDisplay = ddc.ToXml();
         *          currentOrder.Save(Utility.GetUserName());
         *          return;
         *      }
         *
         *      // If total quantity of items is 2, set each to 17.95
         *      if (2 == nTotalQuantity)
         *      {
         *          foreach (OrderItem currentItem in orderItemCollection)
         *          {
         *              if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
         *              {
         *                  currentItem.PricePaid = currentItem.OriginalPrice - 2;
         *                  currentItem.Save(Utility.GetUserName());
         *              }
         *          }
         *          // Add a Column to Order Table to save the collection as Xml to show it later !!!
         *          //currentOrder.DiscountDisplay = ddc.ToXml();
         *          currentOrder.Save(Utility.GetUserName());
         *          return;
         *      }
         *
         * 09/13/09 KPL ***************************************/

        /**** KPL 03/04/08 Commented out due to price change from 29.95 to 19.95
         *              OrderItemCollection orderItemCollection = OrderController.GetCartItems();
         *              Order currentOrder = OrderController.GetCurrentOrder();
         *              int nTotalQuantity = 0;
         *
         *              foreach (OrderItem currentItem in orderItemCollection)
         *              {
         *                  // don't count the free ones when calculating price. KPL 1/6/08
         *                  if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
         *                      nTotalQuantity += currentItem.Quantity;
         *              }
         *                      // If total quantity of items is < 2, reset price to original.
         *                      if (nTotalQuantity < 2)
         *                      {
         *                           // don't count the free ones. KPL 1/6/08
         *                          foreach (OrderItem currentItem in orderItemCollection)
         *                          {
         *                              if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
         *                              {
         *                                  currentItem.PricePaid = currentItem.OriginalPrice;
         *                                  currentItem.Save(Utility.GetUserName());
         *                              }
         *                          }
         *                          // Add a Column to Order Table to save the collection as Xml to show it later !!!
         *                          //currentOrder.DiscountDisplay = ddc.ToXml();
         *                          currentOrder.Save(Utility.GetUserName());
         *                          return;
         *                      }
         *
         *                      // If total quantity of items is 3 or more, set each to 19.99
         *                      if (nTotalQuantity >= 3)
         *                      {
         *                          foreach (OrderItem currentItem in orderItemCollection)
         *                          {
         *                              // if it's a free product, ignore. KPL 01/06/08
         *                              if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
         *                              {
         *                                  currentItem.PricePaid = currentItem.OriginalPrice - 10;
         *                                  currentItem.Save(Utility.GetUserName());
         *                              }
         *                          }
         *                          // Add a Column to Order Table to save the collection as Xml to show it later !!!
         *                          //currentOrder.DiscountDisplay = ddc.ToXml();
         *                          currentOrder.Save(Utility.GetUserName());
         *                          return;
         *                      }
         *
         *                      // If total quantity of items is 2, set each to 24.99
         *                      if (2 == nTotalQuantity)
         *                      {
         *                          foreach (OrderItem currentItem in orderItemCollection)
         *                          {
         *                              if (("LRFreeMale" != currentItem.Sku) && ("LRFreeFemale" != currentItem.Sku))
         *                              {
         *                                  currentItem.PricePaid = currentItem.OriginalPrice - 5;
         *                                  currentItem.Save(Utility.GetUserName());
         *                              }
         *                          }
         *                          // Add a Column to Order Table to save the collection as Xml to show it later !!!
         *                          //currentOrder.DiscountDisplay = ddc.ToXml();
         *                          currentOrder.Save(Utility.GetUserName());
         *                          return;
         *                      }
         **** END KPL 03/04/08 Commented out due to price change from 29.95 to 19.95       ***/

        /***************************************************************** KPL
         * int key = 0;
         * Order currentOrder = OrderController.GetCurrentOrder();
         * Dictionary<int, DiscountDisplay> dic = new Dictionary<int, DiscountDisplay>();
         * foreach (OrderItem currentItem in currentOrder.Items)
         * {
         *  if (currentItem != null)
         *  {
         *      if (!currentItem.PromoCode.StartsWith("BUNDLE:"))
         *      {
         *          key = currentItem.ProductID;
         *          if (!dic.ContainsKey(key))
         *          {
         *              dic.Add(key, new DiscountDisplay(currentItem.Quantity, currentItem.OriginalPrice, currentItem.ProductName));
         *          }
         *          else
         *          {
         *              DiscountDisplay item = new DiscountDisplay();
         *              dic.TryGetValue(key, out item);
         *              dic.Remove(key);
         *              item.Qty = currentItem.Quantity + item.Qty;
         *              dic.Add(key, item);
         *          }
         *      }
         *  }
         * }
         *
         * Dictionary<int, DiscountDisplay>.Enumerator enumerator = dic.GetEnumerator();
         * DiscountDisplayCollection ddc = new DiscountDisplayCollection();
         * while (enumerator.MoveNext())
         * {
         *  DiscountDisplay discount = DiscountDisplay.GetDiscount(enumerator.Current.Key, enumerator.Current.Value.Qty, enumerator.Current.Value.Price);
         *  if (discount != null)
         *  {
         *      //bool display = false;
         *      foreach (OrderItem currentItem in currentOrder.Items)
         *      {
         *          if (currentItem != null)
         *          {
         *              if (currentItem.ProductID == enumerator.Current.Key)
         *              {
         *                  // note:
         *                  // discount.IsActive is checked in the query to the database
         *
         *                  if (discount.IsPercent)
         *                  {
         *                      Product product = new Product(currentItem.ProductID);
         *                      PromotionService.SetProductPricing(product);
         *                      if (discount.Discount > (100 * product.YouSavePercent))
         *                      {
         *                          currentItem.PricePaid = ((currentItem.OriginalPrice - (currentItem.OriginalPrice * (discount.Discount / 100))) + currentItem.AttributesPrice);
         *                          currentItem.Save(Utility.GetUserName());
         *                          //display = true;
         *                      }
         *                      else
         *                      {
         *                          currentItem.PricePaid = product.OurPrice + currentItem.AttributesPrice;
         *                          currentItem.Save(Utility.GetUserName());
         *                      }
         *                  }
         *                  else
         *                  {
         *                      currentItem.PricePaid = (currentItem.OriginalPrice - discount.Discount) + currentItem.AttributesPrice;
         *                      currentItem.Save(Utility.GetUserName());
         *                  }
         *              }
         *          }
         *      }
         *      //if (display)
         *      //    ddc.Add(new DiscountDisplay(discount.Qty, discount.Discount, discount.DiscountAmount, enumerator.Current.Value.Name, discount.IsPercent));
         *  }
         *  else
         *  {
         *      foreach (OrderItem currentItem in currentOrder.Items)
         *      {
         *          if (currentItem != null)
         *          {
         *              if (currentItem.ProductID == enumerator.Current.Key)
         *              {
         *                  if (!currentItem.PromoCode.StartsWith("BUNDLE:"))
         *                  {
         *                      Product product = new Product(enumerator.Current.Key);
         *                      PromotionService.SetProductPricing(product);
         *                      currentItem.PricePaid = product.OurPrice + currentItem.AttributesPrice;
         *                      currentItem.Save(Utility.GetUserName());
         *                  }
         *              }
         *          }
         *      }
         *  }
         * }
         * // Add a Column to Order Table to save the collection as Xml to show it later !!!
         * //currentOrder.DiscountDisplay = ddc.ToXml();
         * currentOrder.Save(Utility.GetUserName());
         ****************************************************KPL ***/
    }
Exemple #20
0
        public static void RefreshForeignKeyTest(string connectionName)
        {
            OrderItemCollection oiColl = new OrderItemCollection();

            oiColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                oiColl.es.Connection.Name = connectionName;
            }

            oiColl.Query.Where(oiColl.Query.OrderID > 11 |
                               oiColl.Query.ProductID > 9);
            oiColl.Query.Load();
            oiColl.MarkAllAsDeleted();
            oiColl.Save();

            OrderCollection oColl = new OrderCollection();

            oColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                oColl.es.Connection.Name = connectionName;
            }

            oColl.Query.Where(oColl.Query.OrderID > 11);
            oColl.Query.Load();
            oColl.MarkAllAsDeleted();
            oColl.Save();

            EmployeeTerritoryCollection etColl = new EmployeeTerritoryCollection();

            etColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                etColl.es.Connection.Name = connectionName;
            }

            etColl.Query.Where(etColl.Query.EmpID > 4 |
                               etColl.Query.TerrID > 4);
            etColl.Query.Load();
            etColl.MarkAllAsDeleted();
            etColl.Save();

            CustomerCollection cColl = new CustomerCollection();

            cColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                cColl.es.Connection.Name = connectionName;
            }

            cColl.Query.Where(cColl.Query.CustomerID > "99999" &
                              cColl.Query.CustomerSub > "001");
            cColl.Query.Load();
            cColl.MarkAllAsDeleted();
            cColl.Save();

            TerritoryExCollection tExColl = new TerritoryExCollection();

            tExColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                tExColl.es.Connection.Name = connectionName;
            }

            tExColl.Query.Where(tExColl.Query.TerritoryID > 1);
            tExColl.Query.Load();
            tExColl.MarkAllAsDeleted();
            tExColl.Save();

            TerritoryCollection tColl = new TerritoryCollection();

            tColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                tColl.es.Connection.Name = connectionName;
            }

            tColl.Query.Where(tColl.Query.TerritoryID > 5);
            tColl.Query.Load();
            tColl.MarkAllAsDeleted();
            tColl.Save();

            ReferredEmployeeCollection reColl = new ReferredEmployeeCollection();

            reColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                reColl.es.Connection.Name = connectionName;
            }

            reColl.Query.Where(reColl.Query.EmployeeID > 4 |
                               reColl.Query.ReferredID > 5);
            reColl.Query.Load();
            reColl.MarkAllAsDeleted();
            reColl.Save();

            ProductCollection pColl = new ProductCollection();

            pColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                pColl.es.Connection.Name = connectionName;
            }

            pColl.Query.Where(pColl.Query.ProductID > 10);
            pColl.Query.Load();
            pColl.MarkAllAsDeleted();
            pColl.Save();

            GroupCollection gColl = new GroupCollection();

            gColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                gColl.es.Connection.Name = connectionName;
            }

            gColl.Query.Where(gColl.Query.Id > "15001");
            gColl.Query.Load();
            gColl.MarkAllAsDeleted();
            gColl.Save();

            EmployeeCollection eColl = new EmployeeCollection();

            eColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                eColl.es.Connection.Name = connectionName;
            }

            eColl.Query.Where(eColl.Query.EmployeeID > 5);
            eColl.Query.Load();
            eColl.MarkAllAsDeleted();
            eColl.Save();

            CustomerGroupCollection cgColl = new CustomerGroupCollection();

            cgColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                cgColl.es.Connection.Name = connectionName;
            }

            cgColl.Query.Where(cgColl.Query.GroupID > "99999" |
                               cgColl.Query.GroupID < "00001");
            cgColl.Query.Load();
            cgColl.MarkAllAsDeleted();
            cgColl.Save();
        }
        private string InitializeAuthRecurringRequest(AuthorizeRecurringTransactionRequest authRequest, string payPeriod, Dictionary <string, string> sensitiveData)
        {
            Payment payment = authRequest.Payment;
            Order   order   = payment.Order;
            User    user    = order.User;

            XmlDocument xmlRequest = new XmlDocument();

            xmlRequest.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TranxRequest />");

            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "MerchantNumber", MerchantNumber);

            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);

            /*string sCurrencyCode = payment.CurrencyCode;
             * if (!("USD".Equals(sCurrencyCode)))
             * {
             *  sCurrencyCode = "CAD";
             * }*/
            string sCurrencyCode = "CAD";

            if (IsUSD)
            {
                sCurrencyCode = "USD";
            }

            string    recurrFlag    = "{RB ";
            LSDecimal recurAmount   = authRequest.RecurringChargeSpecified ? authRequest.RecurringCharge : authRequest.Amount;
            string    startDtString = GetNextPaymentDateStr(authRequest);
            string    duration      = ((int)(authRequest.NumberOfPayments - 1)).ToString();

            recurrFlag += recurAmount.ToString("F2") + " " + startDtString + " " + payPeriod + " " + duration + " email=2}";

            string ccFlag   = "{" + sCurrencyCode + "}";
            string testFlag = (UseTestMode ? "{TEST}" : "");

            string sFlags       = ccFlag + testFlag + recurrFlag;
            string sDescription = authRequest.SubscriptionName; //order.Notes;
            string sAmount      = String.Format("{0:F2}", authRequest.Amount);

            string pline;

            System.Collections.Generic.List <string> arrProducts = new System.Collections.Generic.List <string>();
            if (IncludeOrderItems)
            {
                OrderItemCollection orderItems = order.Items;
                if (orderItems != null && orderItems.Count > 0)
                {
                    foreach (OrderItem orderItem in orderItems)
                    {
                        if (orderItem.OrderItemType == OrderItemType.Product)
                        {
                            pline = "0.00::" + orderItem.Quantity + "::" + MakeSafe(orderItem.Sku, 30) + "::" + MakeSafe(orderItem.Name, 150) + "::" + sFlags;
                            arrProducts.Add(pline);
                        }
                    }
                }
            }

            pline = sAmount + "::1::" + order.OrderNumber + "::" + sDescription + "::" + sFlags;
            arrProducts.Add(pline);

            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "Products", string.Join("|", (string[])arrProducts.ToArray()));
            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxName", accountData["AccountName"]);
            }
            else
            {
                XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxName", order.BillToFirstName + " " + order.BillToLastName);
            }

            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCompany", order.BillToCompany);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxAddress", order.BillToAddress1);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCity", order.BillToCity);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxProvince", order.BillToProvince);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxPostal", order.BillToPostalCode);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCountry", order.BillToCountryCode);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxPhone", order.BillToPhone);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxEmail", order.BillToEmail);


            SetupCreditCardData(xmlRequest, payment, accountData, sensitiveData);

            StringBuilder formData = new StringBuilder();

            formData.Append("xxxRequestMode=X&xxxRequestData=" + HttpUtility.UrlEncode(XmlToString(xmlRequest)));

            return(formData.ToString());
        }
 public OrderItemCollection FetchByID(object OrderItemId)
 {
     OrderItemCollection coll = new OrderItemCollection().Where("OrderItemId", OrderItemId).Load();
     return coll;
 }
 public OrderItemCollection FetchByQuery(Query qry)
 {
     OrderItemCollection coll = new OrderItemCollection();
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
        public void NestedZeroToMany()
        {
            // The main Employee query
            EmployeeQuery eq1 = new EmployeeQuery("e");

            eq1.Where(eq1.EmployeeID < 4);
            eq1.OrderBy(eq1.EmployeeID.Ascending);

            // The Order Collection
            OrderQuery    oq1 = eq1.Prefetch <OrderQuery>(Employee.Prefetch_OrderCollectionByEmployeeID);
            EmployeeQuery eq2 = oq1.GetQuery <EmployeeQuery>();

            oq1.Where(eq2.EmployeeID < 4 && oq1.PlacedBy < 3);

            // Pre-test the Order query
            OrderCollection oColl = new OrderCollection();

            oColl.es.Connection.Name = "ForeignKeyTest";
            oColl.Load(oq1);
            Assert.AreEqual(5, oColl.Count, "Order pre-test");

            // The OrderItem Collection
            OrderItemQuery oiq1 = eq1.Prefetch <OrderItemQuery>(Employee.Prefetch_OrderCollectionByEmployeeID, Order.Prefetch_OrderItemCollectionByOrderID);
            EmployeeQuery  eq3  = oiq1.GetQuery <EmployeeQuery>();
            OrderQuery     oq2  = oiq1.GetQuery <OrderQuery>();

            oiq1.Where(eq3.EmployeeID < 4 && oq2.PlacedBy < 3 && oiq1.Quantity < 100);

            // Pre-test the OrderItem query
            OrderItemCollection oiColl = new OrderItemCollection();

            oiColl.es.Connection.Name = "ForeignKeyTest";
            oiColl.Load(oiq1);
            Assert.AreEqual(4, oiColl.Count, "OrderItem pre-test");

            // Will Prefetch the Order and OrderItems queries
            EmployeeCollection coll = new EmployeeCollection();

            coll.es.Connection.Name = "ForeignKeyTest";
            //coll.es.IsLazyLoadDisabled = true;
            coll.Load(eq1);

            foreach (Employee emp in coll)
            {
                emp.es.IsLazyLoadDisabled = true;

                switch (emp.EmployeeID.Value)
                {
                case 1:
                    Assert.AreEqual(1, emp.EmployeeID.Value);
                    Assert.AreEqual(0, emp.OrderCollectionByEmployeeID.Count);
                    break;

                case 2:
                    Assert.AreEqual(2, emp.EmployeeID.Value);
                    Assert.AreEqual(2, emp.OrderCollectionByEmployeeID.Count);

                    foreach (Order o in emp.OrderCollectionByEmployeeID)
                    {
                        Assert.Less(0, o.OrderItemCollectionByOrderID.Count);
                    }
                    break;

                case 3:
                    Assert.AreEqual(3, emp.EmployeeID.Value);
                    Assert.AreEqual(3, emp.OrderCollectionByEmployeeID.Count);

                    foreach (Order o in emp.OrderCollectionByEmployeeID)
                    {
                        Assert.AreEqual(0, o.OrderItemCollectionByOrderID.Count);
                    }
                    break;

                default:
                    Assert.Fail("Only employees 1, 2, and 3 should be loaded.");
                    break;
                }
            }
        }
Exemple #25
0
        /// <summary>
        /// Generates mail messages for this email template
        /// </summary>
        /// <returns>An array of MailMessage objects generated</returns>
        public MailMessage[] GenerateMailMessages()
        {
            //BUILD AN ARRAY OF MESSAGES TO BE SENT
            List <MailMessage> messages       = new List <MailMessage>();
            NVelocityEngine    velocityEngine = NVelocityEngine.Instance;

            //PARSE THE ADDRESSES
            bool hasVendor;
            List <MailAddress> addressList = this.ParseAddresses(this.ToAddress, out hasVendor);
            List <MailAddress> ccList      = this.ParseAddresses(this.CCList);
            List <MailAddress> bccList     = this.ParseAddresses(this.BCCList);

            //CHECK FOR TO ADDRESSES
            if (addressList.Count > 0)
            {
                //BUILD MESSAGE GOING TO SPECIFIC ADDRESSES
                MailMessage mailMessage = new MailMessage();
                //ADD TO ADDRESSES
                foreach (MailAddress item in addressList)
                {
                    mailMessage.To.Add(item);
                }
                //ADD CC ADDRESSES
                foreach (MailAddress item in ccList)
                {
                    mailMessage.CC.Add(item);
                }
                //ADD BCC ADDRESSES
                foreach (MailAddress item in bccList)
                {
                    mailMessage.Bcc.Add(item);
                }
                //SET FROM ADDRESS
                mailMessage.From = new MailAddress(this.FromAddress);
                //PROCESS THE SUBJECT AND BODY
                mailMessage.Subject    = velocityEngine.Process(this.Parameters, this.Subject);
                mailMessage.Body       = velocityEngine.Process(this.Parameters, this.Body);
                mailMessage.IsBodyHtml = this.IsHTML;
                messages.Add(mailMessage);
            }

            //PROCESS VENDOR MESSAGES IF WE HAVE AN ORDER CONTEXT
            if (hasVendor && this.Parameters.ContainsKey("order"))
            {
                Order order = (Order)this.Parameters["order"];
                //DECIDE WHICH VENDORS NEED TO HAVE MESSAGES COMPILED
                VendorCollection vendors = VendorDataSource.LoadForOrder(order.OrderId);
                if (vendors.Count > 0)
                {
                    //VENDORS ARE FOUND, WE MUST COMPILE ONE MESSAGE FOR EACH VENDOR
                    foreach (Vendor vendor in vendors)
                    {
                        List <string> emailList = GetValidEmailList(vendor.Email);
                        if (emailList != null && emailList.Count > 0)
                        {
                            //BUILD VENDOR SPECIFIC ITEM COLLECTIONS
                            OrderItemCollection vendorItems            = new OrderItemCollection();
                            OrderItemCollection vendorNonShippingItems = new OrderItemCollection();
                            foreach (OrderItem item in order.Items)
                            {
                                if (item.Product != null)
                                {
                                    //SEE IF THIS IS A PRODUCT THAT BELONGS TO THE VENDOR
                                    if (item.Product.VendorId == vendor.VendorId)
                                    {
                                        vendorItems.Add(item);
                                        if (item.OrderShipmentId == 0)
                                        {
                                            vendorNonShippingItems.Add(item);
                                        }
                                    }
                                }
                                else
                                {
                                    //SEE IF THIS IS A NON-PRODUCT ITEM THAT APPLIES
                                    //E.G. A DISCOUNT ON A VENDOR ITEM
                                    if (vendorItems.IndexOf(item.ParentItemId) > -1)
                                    {
                                        vendorItems.Add(item);
                                        if (item.OrderShipmentId == 0)
                                        {
                                            vendorNonShippingItems.Add(item);
                                        }
                                    }
                                }
                            }
                            //BUILD VENDOR SPECIFIC SHIPMENT COLLECTION
                            OrderShipmentCollection vendorShipments = new OrderShipmentCollection();
                            foreach (OrderItem item in vendorItems)
                            {
                                if ((item.OrderShipment != null) && (vendorShipments.IndexOf(item.OrderShipmentId) < 0))
                                {
                                    vendorShipments.Add(item.OrderShipment);
                                }
                            }
                            //CREATE VENDOR SPECIFIC PARAMETERS
                            Hashtable vendorParameters = new Hashtable(this.Parameters);
                            vendorParameters["Vendor"]                 = vendor;
                            vendorParameters["VendorShipments"]        = vendorShipments;
                            vendorParameters["VendorItems"]            = vendorItems;
                            vendorParameters["VendorNonShippingItems"] = vendorNonShippingItems;
                            //COMPILE VENDOR SPECIFIC MAIL MESSAGE
                            MailMessage mailMessage = new MailMessage();
                            //ADD TO ADDRESSES
                            foreach (string email in emailList)
                            {
                                mailMessage.To.Add(email);
                            }
                            //ADD CC ADDRESSES
                            foreach (MailAddress item in ccList)
                            {
                                mailMessage.CC.Add(item);
                            }
                            //ADD BCC ADDRESSES
                            foreach (MailAddress item in bccList)
                            {
                                mailMessage.Bcc.Add(item);
                            }
                            //SET FROM ADDRESS
                            mailMessage.From = new MailAddress(this.FromAddress);
                            //PROCESS THE SUBJECT AND BODY
                            mailMessage.Subject    = velocityEngine.Process(vendorParameters, this.Subject);
                            mailMessage.Body       = velocityEngine.Process(vendorParameters, this.Body);
                            mailMessage.IsBodyHtml = this.IsHTML;
                            messages.Add(mailMessage);
                        }
                        else
                        {
                            Logger.Warn("Could not process vendor notification for '" + vendor.Name + "'; email address is invalid.");
                        }
                    }
                }
            }
            else
            if (hasVendor && this.Parameters.ContainsKey("vendors"))
            {
                Vendor[]         vendors  = (Vendor[])this.Parameters["vendors"];
                Product[]        products = (Product[])this.Parameters["products"];
                ProductVariant[] variants = (ProductVariant[])this.Parameters["variants"];

                if (vendors != null && vendors.Length > 0)
                {
                    foreach (Vendor vendor in vendors)
                    {
                        List <string> emailList = GetValidEmailList(vendor.Email);
                        if (emailList != null && emailList.Count > 0)
                        {
                            List <Product>        vendorProducts = new List <Product>();
                            List <ProductVariant> vendorVariants = new List <ProductVariant>();

                            if (products != null)
                            {
                                foreach (Product product in products)
                                {
                                    if (product.Vendor != null && product.VendorId == vendor.VendorId)
                                    {
                                        vendorProducts.Add(product);
                                    }
                                }
                            }

                            if (variants != null)
                            {
                                foreach (ProductVariant variant in variants)
                                {
                                    if (variant.Product.Vendor != null && variant.Product.Vendor.VendorId == vendor.VendorId)
                                    {
                                        vendorVariants.Add(variant);
                                    }
                                }
                            }

                            //CREATE VENDOR SPECIFIC PARAMETERS
                            Hashtable vendorParameters = new Hashtable(this.Parameters);
                            vendorParameters["vendor"]   = vendor;
                            vendorParameters["products"] = vendorProducts;
                            vendorParameters["variants"] = vendorVariants;

                            //COMPILE VENDOR SPECIFIC MAIL MESSAGE
                            MailMessage mailMessage = new MailMessage();
                            //ADD TO ADDRESSES
                            foreach (string email in emailList)
                            {
                                mailMessage.To.Add(email);
                            }
                            //ADD CC ADDRESSES
                            foreach (MailAddress item in ccList)
                            {
                                mailMessage.CC.Add(item);
                            }
                            //ADD BCC ADDRESSES
                            foreach (MailAddress item in bccList)
                            {
                                mailMessage.Bcc.Add(item);
                            }
                            //SET FROM ADDRESS
                            mailMessage.From = new MailAddress(this.FromAddress);
                            //PROCESS THE SUBJECT AND BODY
                            mailMessage.Subject    = velocityEngine.Process(vendorParameters, this.Subject);
                            mailMessage.Body       = velocityEngine.Process(vendorParameters, this.Body);
                            mailMessage.IsBodyHtml = this.IsHTML;
                            messages.Add(mailMessage);
                        }
                        else
                        {
                            Logger.Warn("Could not process vendor notification for '" + vendor.Name + "'; email address is invalid.");
                        }
                    }
                }
            }

            //RETURN THE GENERATED MAIL MESSAGE
            if (messages.Count == 0)
            {
                return(null);
            }
            return(messages.ToArray());
        }