void GenerateOrders(bool testMode) { var orders = testMode ? hccRecurringOrder.GetTestExpiringOrders() : hccRecurringOrder.GetExpiringOrders(); litNoOrders.Visible = orders.Count == 0; //Invoke Method to Call SP [hcc_CloneOrder] use the output parameter to call ProcessNewOrder in the line below... using (var hcE = new healthychefEntities()) { var ordersAdded = new List <int>(); foreach (var order in orders) { var newCartId = new ObjectParameter("newCartID", typeof(int)); var taxRate = 0.00m; var customer = hccUserProfile.GetById(order.UserProfileID ?? 0); if (customer != null) { var shippingAddr = hccAddress.GetById(customer.ShippingAddressID ?? 0); taxRate = GetProfileTaxRate(shippingAddr); } hcE.hcc_CloneOrder(order.CartID, order.CartItemID, taxRate, newCartId); ordersAdded.Add((int)newCartId.Value); } //Unique Orders if (ordersAdded.Count > 0) { var ordersToProcess = ordersAdded.Distinct(); foreach (var order in ordersToProcess) { ProcessNewOrder(order); } } //lvAllRecurringOrders.DataSource = hcE.hcc_RecurringOrderByDeliveryDate().ToList(); //lvAllRecurringOrders.DataBind(); } // Output the number of orders that are processed if (orders.Count > 0) { litNumRecurringLabel.Visible = true; litNumRecurringOrders.Text = orders.Count.ToString(); litNumRecurringOrders.Visible = true; } }