public static List <AggrCartItem> GetFromRange(List <hccCartItem> cartItems, bool includeSnapshots)
        {
            List <AggrCartItem> aggrCartItems = new List <AggrCartItem>();

            foreach (hccCartItem cartItem in cartItems)
            {
                if (cartItem.ItemType == Common.Enums.CartItemType.GiftCard)
                {
                    AggrCartItem ag = aggrCartItems.SingleOrDefault(a => a.CartItem.OrderNumber == cartItem.OrderNumber);

                    if (ag == null)
                    {
                        ag = new AggrCartItem(cartItem, includeSnapshots);
                        aggrCartItems.Add(ag);
                    }

                    ag.TotalQuantity += cartItem.Quantity;
                }

                if (cartItem.ItemType == Common.Enums.CartItemType.AlaCarte)
                {
                    AggrCartItem ag;

                    if (!aggrCartItems.Any(a => a.CartItem.OrderNumber == cartItem.OrderNumber))
                    {
                        ag = aggrCartItems.SingleOrDefault(a => a.CartItem.OrderNumber == cartItem.OrderNumber);
                    }
                    else
                    {
                        ag = aggrCartItems.SingleOrDefault(a => a.CartItem.OrderNumber == cartItem.OrderNumber);
                    }

                    if (ag == null)
                    {
                        ag = new AggrCartItem(cartItem, includeSnapshots);
                        aggrCartItems.Add(ag);
                    }
                    else
                    {
                        ag.AddCartItem(cartItem);
                    }

                    ag.ALC_Count++;
                    ag.TotalQuantity += cartItem.Quantity;
                }
            }

            return(aggrCartItems);
        }
        public static List <AggrCartItem> Search(string lastName, string email, int?purchNum, DateTime?deliveryDate, bool includeSnapshots, bool includeGiftCerts)
        {
            try
            {
                using (var cont = new healthychefEntities())
                {
                    List <AggrCartItem> aggrItems = new List <AggrCartItem>();

                    List <hccCartItem> alcgc;

                    if (includeGiftCerts)
                    {
                        alcgc = cont.hcc_OrderFulfillSearch_ALCnGC(deliveryDate, purchNum, lastName, email).Select(x => new hccCartItem
                        {
                            CartItemID              = x.CartItemID,
                            CartID                  = Convert.ToInt32(x.CartID),
                            UserProfileID           = Convert.ToInt32(x.UserProfileID),
                            ItemTypeID              = Convert.ToInt32(x.ItemTypeID),
                            ItemName                = x.ItemName,
                            ItemDesc                = x.ItemDesc,
                            ItemPrice               = Convert.ToDecimal(x.ItemPrice),
                            Quantity                = Convert.ToInt32(x.Quantity),
                            IsTaxable               = Convert.ToBoolean(x.IsTaxable),
                            OrderNumber             = x.OrderNumber,
                            DeliveryDate            = Convert.ToDateTime(x.DeliveryDate),
                            Gift_RedeemCode         = x.Gift_RedeemCode,
                            Gift_IssuedTo           = x.Gift_IssuedTo,
                            Gift_IssuedDate         = x.Gift_IssuedDate,
                            Gift_RedeemedBy         = x.Gift_RedeemedBy,
                            Gift_RedeemedDate       = x.Gift_RedeemedDate,
                            Gift_RecipientAddressId = x.Gift_RecipientAddressId,
                            Gift_RecipientEmail     = x.Gift_RecipientEmail,
                            Gift_RecipientMessage   = x.Gift_RecipientMessage,
                            Meal_MenuItemID         = x.Meal_MenuItemID,
                            Meal_MealSizeID         = x.Meal_MealSizeID,
                            Meal_ShippingCost       = x.Meal_ShippingCost,
                            Plan_PlanID             = x.Plan_PlanID,
                            Plan_ProgramOptionID    = x.Plan_ProgramOptionID,
                            Plan_IsAutoRenew        = x.Plan_IsAutoRenew,
                            CreatedBy               = x.CreatedBy,
                            CreatedDate             = Convert.ToDateTime(x.CreatedDate),
                            IsCompleted             = Convert.ToBoolean(x.IsCompleted),
                            IsCancelled             = Convert.ToBoolean(x.IsCancelled),
                            IsFulfilled             = Convert.ToBoolean(x.IsFulfilled),
                            DiscountPerEach         = Convert.ToDecimal(x.DiscountPerEach),
                            DiscountAdjPrice        = Convert.ToDecimal(x.DiscountAdjPrice),
                            SnapBillAddrId          = x.SnapBillAddrId,
                            SnapShipAddrId          = x.SnapShipAddrId,
                            TaxRate                 = x.TaxRate,
                            TaxableAmount           = x.TaxableAmount,
                            DiscretionaryTaxAmount  = x.DiscretionaryTaxAmount,
                            TaxRateAssigned         = x.TaxRateAssigned
                        }).ToList();
                    }
                    else
                    {
                        alcgc = cont.hcc_OrderFulfillSearch_ALCnGC(deliveryDate, purchNum, lastName, email).ToList().Where(a => a.ItemTypeID != Convert.ToInt32(Enums.CartItemType.GiftCard)).Select(x => new hccCartItem
                        {
                            CartItemID              = x.CartItemID,
                            CartID                  = Convert.ToInt32(x.CartID),
                            UserProfileID           = Convert.ToInt32(x.UserProfileID),
                            ItemTypeID              = Convert.ToInt32(x.ItemTypeID),
                            ItemName                = x.ItemName,
                            ItemDesc                = x.ItemDesc,
                            ItemPrice               = Convert.ToDecimal(x.ItemPrice),
                            Quantity                = Convert.ToInt32(x.Quantity),
                            IsTaxable               = Convert.ToBoolean(x.IsTaxable),
                            OrderNumber             = x.OrderNumber,
                            DeliveryDate            = Convert.ToDateTime(x.DeliveryDate),
                            Gift_RedeemCode         = x.Gift_RedeemCode,
                            Gift_IssuedTo           = x.Gift_IssuedTo,
                            Gift_IssuedDate         = x.Gift_IssuedDate,
                            Gift_RedeemedBy         = x.Gift_RedeemedBy,
                            Gift_RedeemedDate       = x.Gift_RedeemedDate,
                            Gift_RecipientAddressId = x.Gift_RecipientAddressId,
                            Gift_RecipientEmail     = x.Gift_RecipientEmail,
                            Gift_RecipientMessage   = x.Gift_RecipientMessage,
                            Meal_MenuItemID         = x.Meal_MenuItemID,
                            Meal_MealSizeID         = x.Meal_MealSizeID,
                            Meal_ShippingCost       = x.Meal_ShippingCost,
                            Plan_PlanID             = x.Plan_PlanID,
                            Plan_ProgramOptionID    = x.Plan_ProgramOptionID,
                            Plan_IsAutoRenew        = x.Plan_IsAutoRenew,
                            CreatedBy               = x.CreatedBy,
                            CreatedDate             = Convert.ToDateTime(x.CreatedDate),
                            IsCompleted             = Convert.ToBoolean(x.IsCompleted),
                            IsCancelled             = Convert.ToBoolean(x.IsCancelled),
                            IsFulfilled             = Convert.ToBoolean(x.IsFulfilled),
                            DiscountPerEach         = Convert.ToDecimal(x.DiscountPerEach),
                            DiscountAdjPrice        = Convert.ToDecimal(x.DiscountAdjPrice),
                            SnapBillAddrId          = x.SnapBillAddrId,
                            SnapShipAddrId          = x.SnapShipAddrId,
                            TaxRate                 = x.TaxRate,
                            TaxableAmount           = x.TaxableAmount,
                            DiscretionaryTaxAmount  = x.DiscretionaryTaxAmount,
                            TaxRateAssigned         = x.TaxRateAssigned
                        }).ToList();
                    }

                    aggrItems.AddRange(AggrCartItem.GetFromRange(alcgc, includeSnapshots));

                    List <hccCartItemCalendar> progs = cont.hcc_OrderFulfillSearch_Programs(deliveryDate, purchNum, lastName, email).ToList();

                    aggrItems.AddRange(AggrCartItem.GetFromRange(progs, includeSnapshots));

                    return(aggrItems);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }