Пример #1
0
        public static List <MOTCartItem> GetFromCartCalendarForWaaG(hccCartItemCalendar cartCal)
        {
            List <MOTCartItem>           retMotItems = new List <MOTCartItem>();
            hccCartItem                  cartItem    = hccCartItem.GetById(cartCal.CartItemID);
            hccProductionCalendar        prodCal     = hccProductionCalendar.GetById(cartCal.CalendarID);
            hccProgramPlan               plan        = hccProgramPlan.GetById(cartItem.Plan_PlanID.Value);
            List <hccProgramDefaultMenu> defMenus    = hccProgramDefaultMenu.GetBy(cartCal.CalendarID, plan.ProgramID);
            List <hccMenuItem>           planMeals   = new List <hccMenuItem>();

            defMenus.ForEach(delegate(hccProgramDefaultMenu defMenu)
            {
                hccCartDefaultMenuException cartDefMenuEx = hccCartDefaultMenuException.GetBy(defMenu.DefaultMenuID, cartCal.CartCalendarID);

                hccMenuItem selItem;
                Enums.CartItemSize selPortionSize;
                string prefsString = string.Empty;

                if (cartDefMenuEx == null)
                {
                    selItem        = hccMenuItem.GetById(defMenu.MenuItemID);
                    selPortionSize = (Enums.CartItemSize)defMenu.MenuItemSizeID;
                    prefsString    = "None";
                }
                else
                {
                    selItem        = hccMenuItem.GetById(cartDefMenuEx.MenuItemID);
                    selPortionSize = (Enums.CartItemSize)cartDefMenuEx.MenuItemSizeID;
                    prefsString    = hccCartDefaultMenuExPref.GetPrefsBy(cartDefMenuEx.DefaultMenuExceptID)
                                     .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d);
                }

                MOTCartItem curMotItem = null;

                if (selItem != null)
                {
                    if (selPortionSize == Enums.CartItemSize.NoSize)
                    {
                        selPortionSize = Enums.CartItemSize.RegularSize;
                    }

                    curMotItem = new MOTCartItem
                    {
                        CartItem     = cartItem,
                        CartItemId   = cartItem.CartItemID,
                        CustomerName = cartItem.UserProfile.ParentProfileName,
                        OrderNumber  = cartItem.OrderNumber,
                        DeliveryDate = prodCal.DeliveryDate,
                        DayNumber    = defMenu.DayNumber,
                        ItemName     = selItem.Name,
                        MealType     = selItem.MealType,
                        PortionSize  = Enums.GetEnumDescription(selPortionSize),
                        Preferences  = prefsString,
                        ProfileName  = cartItem.UserProfile.ProfileName,
                        Servings     = cartItem.Quantity.ToString()
                    };

                    retMotItems.Add(curMotItem);
                }
            });

            return(retMotItems);
        }
Пример #2
0
        public static List <MOTCartItem> GetFromCartCalendar(hccCartItemCalendar cartCal)
        {
            List <MOTCartItem>           retMotItems = new List <MOTCartItem>();
            hccCartItem                  cartItem    = hccCartItem.GetById(cartCal.CartItemID);
            hccProductionCalendar        prodCal     = hccProductionCalendar.GetById(cartCal.CalendarID);
            hccProgramPlan               plan        = hccProgramPlan.GetById(cartItem.Plan_PlanID.Value);
            List <hccProgramDefaultMenu> defMenus    = hccProgramDefaultMenu.GetBy(cartCal.CalendarID, plan.ProgramID);
            List <hccMenuItem>           planMeals   = new List <hccMenuItem>();

            defMenus.ForEach(delegate(hccProgramDefaultMenu defMenu)
            {
                hccCartDefaultMenuException cartDefMenuEx = hccCartDefaultMenuException.GetBy(defMenu.DefaultMenuID, cartCal.CartCalendarID);

                hccMenuItem selItem;
                Enums.CartItemSize selPortionSize;
                string prefsString = string.Empty;

                // Get the current menuItem
                if (cartDefMenuEx == null)
                {
                    selItem        = hccMenuItem.GetById(defMenu.MenuItemID);
                    selPortionSize = (Enums.CartItemSize)defMenu.MenuItemSizeID;
                    prefsString    = "None";
                }
                else
                {
                    selItem        = hccMenuItem.GetById(cartDefMenuEx.MenuItemID);
                    selPortionSize = (Enums.CartItemSize)cartDefMenuEx.MenuItemSizeID;
                    prefsString    = hccCartDefaultMenuExPref.GetPrefsBy(cartDefMenuEx.DefaultMenuExceptID)
                                     .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d);
                }

                MOTCartItem curMotItem = null;

                if (selItem != null)
                {
                    if (selPortionSize == Enums.CartItemSize.NoSize)
                    {
                        selPortionSize = Enums.CartItemSize.RegularSize;
                    }

                    // determine if current item is an Entree or side
                    if (selItem.MealType == Enums.MealTypes.BreakfastEntree ||
                        selItem.MealType == Enums.MealTypes.LunchEntree ||
                        selItem.MealType == Enums.MealTypes.DinnerEntree ||
                        selItem.MealType == Enums.MealTypes.OtherEntree ||
                        selItem.MealType == Enums.MealTypes.ChildEntree ||
                        selItem.MealType == Enums.MealTypes.Beverage ||
                        selItem.MealType == Enums.MealTypes.Dessert ||
                        selItem.MealType == Enums.MealTypes.Goods ||
                        selItem.MealType == Enums.MealTypes.Miscellaneous ||
                        selItem.MealType == Enums.MealTypes.Salad ||
                        selItem.MealType == Enums.MealTypes.Snack ||
                        selItem.MealType == Enums.MealTypes.Soup ||
                        selItem.MealType == Enums.MealTypes.Supplement)
                    {   // Entrees
                        // determine if this type of entree has been added in previous loop
                        curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber &&
                                                                a.MealType == selItem.MealType);

                        if (curMotItem == null)
                        {
                            //if not added in previous loop, add new
                            curMotItem = new MOTCartItem
                            {
                                MenuItem     = selItem,
                                CartItem     = cartItem,
                                CartItemId   = cartItem.CartItemID,
                                CustomerName = cartItem.UserProfile.ParentProfileName,
                                OrderNumber  = cartItem.OrderNumber,
                                DeliveryDate = prodCal.DeliveryDate,
                                DayNumber    = defMenu.DayNumber,
                                ItemName     = selItem.Name,
                                MealType     = selItem.MealType,
                                PortionSize  = Enums.GetEnumDescription(selPortionSize),
                                Preferences  = prefsString,
                                ProfileName  = cartItem.UserProfile.ProfileName,
                                Servings     = cartItem.Quantity.ToString(),
                            };

                            retMotItems.Add(curMotItem);
                        }
                        else
                        {
                            //if entree added in previous loop, add as a side
                            curMotItem.Sides += selPortionSize + " - " + selItem.Name;
                        }
                    }
                    else
                    {   // Sides
                        // get parent entree type
                        Enums.MealTypes parentType = Enums.MealTypes.Unknown;

                        if (selItem.MealType == Enums.MealTypes.BreakfastSide)
                        {
                            parentType = Enums.MealTypes.BreakfastEntree;
                        }
                        else if (selItem.MealType == Enums.MealTypes.LunchSide)
                        {
                            parentType = Enums.MealTypes.LunchEntree;
                        }
                        else if (selItem.MealType == Enums.MealTypes.DinnerSide)
                        {
                            parentType = Enums.MealTypes.DinnerEntree;
                        }
                        else if (selItem.MealType == Enums.MealTypes.OtherSide)
                        {
                            parentType = Enums.MealTypes.OtherEntree;
                        }
                        else if (selItem.MealType == Enums.MealTypes.ChildSide)
                        {
                            parentType = Enums.MealTypes.ChildEntree;
                        }

                        // determine if this type of entree has been added in previous loop
                        curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber &&
                                                                a.MealType == parentType);

                        if (curMotItem == null)
                        {
                            curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber);

                            if (curMotItem == null)
                            {
                                curMotItem = new MOTCartItem
                                {
                                    MenuItem     = selItem,
                                    CartItem     = cartItem,
                                    CartItemId   = cartItem.CartItemID,
                                    CustomerName = cartItem.UserProfile.ParentProfileName,
                                    OrderNumber  = cartItem.OrderNumber,
                                    DeliveryDate = prodCal.DeliveryDate,
                                    DayNumber    = defMenu.DayNumber,
                                    ItemName     = selItem.Name,
                                    MealType     = selItem.MealType,
                                    PortionSize  = Enums.GetEnumDescription(selPortionSize),
                                    Preferences  = prefsString,
                                    ProfileName  = cartItem.UserProfile.ProfileName,
                                    Servings     = cartItem.Quantity.ToString(),
                                    Sides        = "NoneB"
                                };


                                retMotItems.Add(curMotItem);
                            }
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(curMotItem.Sides))
                            {
                                curMotItem.Sides += selItem.Name;

                                if (prefsString != "None" && !string.IsNullOrWhiteSpace(prefsString))
                                {
                                    curMotItem.Sides += " (" + prefsString + ")";
                                }
                            }
                            else
                            {
                                curMotItem.Sides += ", " + selItem.Name;

                                if (prefsString != "None" && !string.IsNullOrWhiteSpace(prefsString))
                                {
                                    curMotItem.Sides += " (" + prefsString + ")";
                                }
                            }
                        }
                    }
                }
            });

            return(retMotItems);
        }
Пример #3
0
        public static List <MOTCartItem> GetFromCartCalendarForMOT(hccCartItemCalendar cartCal)
        {
            try
            {
                List <MOTCartItem> retMotItems  = new List <MOTCartItem>();
                List <MOTCartItem> addlMotItems = new List <MOTCartItem>();

                hccCartItem                  cartItem  = hccCartItem.GetById(cartCal.CartItemID);
                hccProductionCalendar        prodCal   = hccProductionCalendar.GetById(cartCal.CalendarID);
                hccProgramPlan               plan      = hccProgramPlan.GetById(cartItem.Plan_PlanID.Value);
                List <hccProgramDefaultMenu> defMenus  = hccProgramDefaultMenu.GetBy(cartCal.CalendarID, plan.ProgramID, plan.NumDaysPerWeek);
                List <hccMenuItem>           planMeals = new List <hccMenuItem>();

                defMenus.ForEach(delegate(hccProgramDefaultMenu defMenu)
                {
                    hccCartDefaultMenuException cartDefMenuEx = hccCartDefaultMenuException.GetBy(defMenu.DefaultMenuID, cartCal.CartCalendarID);

                    hccMenuItem selItem;
                    Enums.CartItemSize selPortionSize = Enums.CartItemSize.NoSize;
                    string prefsString = string.Empty;

                    if (cartDefMenuEx == null)
                    {
                        selItem        = hccMenuItem.GetById(defMenu.MenuItemID);
                        selPortionSize = (Enums.CartItemSize)defMenu.MenuItemSizeID;
                        prefsString    = "None";
                    }
                    else
                    {
                        selItem        = hccMenuItem.GetById(cartDefMenuEx.MenuItemID);
                        selPortionSize = (Enums.CartItemSize)cartDefMenuEx.MenuItemSizeID;

                        try
                        {
                            prefsString = string.Empty;
                            List <hccPreference> prefs = hccCartDefaultMenuExPref.GetPrefsBy(cartDefMenuEx.DefaultMenuExceptID);
                            prefsString = prefs.Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }

                    if (selPortionSize == Enums.CartItemSize.NoSize)
                    {
                        selPortionSize = Enums.CartItemSize.RegularSize;
                    }

                    MOTCartItem curMotItem = null;

                    if (selItem != null)
                    {
                        if (selItem.MealType == Enums.MealTypes.BreakfastEntree ||
                            selItem.MealType == Enums.MealTypes.LunchEntree ||
                            selItem.MealType == Enums.MealTypes.DinnerEntree ||
                            selItem.MealType == Enums.MealTypes.ChildEntree ||
                            selItem.MealType == Enums.MealTypes.Beverage ||
                            selItem.MealType == Enums.MealTypes.Dessert ||
                            selItem.MealType == Enums.MealTypes.Goods ||
                            selItem.MealType == Enums.MealTypes.Miscellaneous ||
                            selItem.MealType == Enums.MealTypes.Salad ||
                            selItem.MealType == Enums.MealTypes.Snack ||
                            selItem.MealType == Enums.MealTypes.Soup ||
                            selItem.MealType == Enums.MealTypes.Supplement)
                        {
                            curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber &&
                                                                    a.MealType == selItem.MealType);

                            if (curMotItem == null || curMotItem.MealType == Enums.MealTypes.Snack)
                            {
                                curMotItem = new MOTCartItem
                                {
                                    CartItem     = cartItem,
                                    CartItemId   = cartItem.CartItemID,
                                    CustomerName = cartItem.UserProfile.ParentProfileName,
                                    OrderNumber  = cartItem.OrderNumber + "-PRG",
                                    DeliveryDate = prodCal.DeliveryDate,
                                    DayNumber    = defMenu.DayNumber,
                                    ItemName     = selItem.Name,
                                    MealType     = selItem.MealType,
                                    PortionSize  = Enums.GetEnumDescription(selPortionSize),
                                    Preferences  = prefsString,
                                    ProfileName  = cartItem.UserProfile != null ? cartItem.UserProfile.ProfileName : string.Empty,
                                    Servings     = cartItem.Quantity.ToString(),
                                    MenuItem     = selItem,
                                    Quantity     = cartItem.Quantity,
                                    Sides        = "None"
                                };

                                if (cartItem.SnapShipAddrId.HasValue)
                                {
                                    hccAddress addr           = hccAddress.GetById(cartItem.SnapShipAddrId.Value);
                                    curMotItem.DeliveryMethod = ((Enums.DeliveryTypes)addr.DefaultShippingTypeID).ToString();
                                }

                                retMotItems.Add(curMotItem);
                            }
                            else
                            {
                                curMotItem.Sides += selPortionSize + " - " + selItem.Name;
                            }
                        }
                        else
                        {
                            // get parent entree type
                            Enums.MealTypes parentType = Enums.MealTypes.Unknown;

                            if (selItem.MealType == Enums.MealTypes.BreakfastSide)
                            {
                                parentType = Enums.MealTypes.BreakfastEntree;
                            }
                            else if (selItem.MealType == Enums.MealTypes.LunchSide)
                            {
                                parentType = Enums.MealTypes.LunchEntree;
                            }
                            else if (selItem.MealType == Enums.MealTypes.DinnerSide)
                            {
                                parentType = Enums.MealTypes.DinnerEntree;
                            }
                            else if (selItem.MealType == Enums.MealTypes.OtherSide)
                            {
                                parentType = Enums.MealTypes.OtherEntree;
                            }
                            else if (selItem.MealType == Enums.MealTypes.ChildSide)
                            {
                                parentType = Enums.MealTypes.ChildEntree;
                            }

                            curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber &&
                                                                    a.MealType == parentType);

                            if (curMotItem == null)
                            {
                                curMotItem = retMotItems.FirstOrDefault(a => a.DayNumber == defMenu.DayNumber);

                                if (curMotItem == null)
                                {
                                    curMotItem = new MOTCartItem
                                    {
                                        CartItem     = cartItem,
                                        CartItemId   = cartItem.CartItemID,
                                        CustomerName = cartItem.UserProfile.ParentProfileName,
                                        OrderNumber  = cartItem.OrderNumber + "-PRG",
                                        DeliveryDate = prodCal.DeliveryDate,
                                        DayNumber    = defMenu.DayNumber,
                                        ItemName     = selItem.Name,
                                        MealType     = selItem.MealType,
                                        PortionSize  = Enums.GetEnumDescription(selPortionSize),
                                        Preferences  = prefsString,
                                        ProfileName  = cartItem.UserProfile != null ? cartItem.UserProfile.ProfileName : string.Empty,
                                        Servings     = cartItem.Quantity.ToString(),
                                        MenuItem     = selItem,
                                        Quantity     = cartItem.Quantity,
                                        Sides        = "None"
                                    };

                                    if (cartItem.SnapShipAddrId.HasValue)
                                    {
                                        hccAddress addr           = hccAddress.GetById(cartItem.SnapShipAddrId.Value);
                                        curMotItem.DeliveryMethod = ((Enums.DeliveryTypes)addr.DefaultShippingTypeID).ToString();
                                    }

                                    retMotItems.Add(curMotItem);
                                }
                            }
                            else
                            {
                                if (string.IsNullOrWhiteSpace(curMotItem.Sides))
                                {
                                    curMotItem.Sides = selItem.Name;

                                    if (prefsString != "None" && !string.IsNullOrWhiteSpace(prefsString))
                                    {
                                        curMotItem.Sides += " (" + prefsString + ")";
                                    }
                                }
                                else
                                {
                                    if (curMotItem.Sides == "None")
                                    {
                                        curMotItem.Sides = selItem.Name;
                                    }
                                    else
                                    {
                                        curMotItem.Sides += ", " + selItem.Name;
                                    }

                                    if (prefsString != "None" && !string.IsNullOrWhiteSpace(prefsString))
                                    {
                                        curMotItem.Sides += " (" + prefsString + ")";
                                    }
                                }
                            }
                        }
                    }
                });

                List <MOTCartItem> removeDupItems = new List <MOTCartItem>();

                retMotItems.ForEach(delegate(MOTCartItem motItem)
                {
                    if (motItem.MealType == Enums.MealTypes.BreakfastEntree ||
                        motItem.MealType == Enums.MealTypes.LunchEntree ||
                        motItem.MealType == Enums.MealTypes.DinnerEntree ||
                        motItem.MealType == Enums.MealTypes.ChildEntree ||
                        motItem.MealType == Enums.MealTypes.Beverage ||
                        motItem.MealType == Enums.MealTypes.Dessert ||
                        motItem.MealType == Enums.MealTypes.Goods ||
                        motItem.MealType == Enums.MealTypes.Miscellaneous ||
                        motItem.MealType == Enums.MealTypes.Salad ||
                        motItem.MealType == Enums.MealTypes.Snack ||
                        motItem.MealType == Enums.MealTypes.Soup ||
                        motItem.MealType == Enums.MealTypes.Supplement)
                    {
                        if (motItem.CartItem.Quantity > 1)
                        {
                            for (int i = 1; i <= motItem.CartItem.Quantity; i++)
                            {
                                MOTCartItem copyMotItem = new MOTCartItem
                                {
                                    CartItem       = motItem.CartItem,
                                    CartItemId     = motItem.CartItemId,
                                    OrderNumber    = motItem.OrderNumber,
                                    DeliveryDate   = motItem.DeliveryDate,
                                    CustomerName   = motItem.CustomerName,
                                    DayNumber      = motItem.DayNumber,
                                    ItemName       = motItem.ItemName,
                                    MealType       = motItem.MealType,
                                    PortionSize    = motItem.PortionSize,
                                    Preferences    = motItem.Preferences,
                                    ProfileName    = motItem.ProfileName,
                                    MenuItem       = motItem.MenuItem,
                                    Index          = motItem.Index,
                                    Quantity       = motItem.Quantity,
                                    Sides          = motItem.Sides,
                                    DeliveryMethod = motItem.DeliveryMethod,
                                    Servings       = "1" //motItem.Servings
                                };

                                addlMotItems.Add(copyMotItem);
                            }

                            removeDupItems.Add(motItem);
                        }
                    }
                });

                if (addlMotItems.Count > 0)
                {
                    retMotItems.AddRange(addlMotItems);
                }

                if (removeDupItems.Count > 0)
                {
                    removeDupItems.ForEach(a => retMotItems.Remove(a));
                }

                var t = retMotItems.ToList();
                return(t);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public static List <MOTCartItem> Search_MealOrderTicketForMOT(DateTime?startDate, DateTime?endDate)
        {
            try
            {
                using (var cont = new healthychefEntities())
                {
                    List <MOTCartItem> motItems = new List <MOTCartItem>();

                    List <hccCartItem> alcgc = cont.hcc_OrderFulfillSearch_ALCnGC_ByRange(startDate, endDate).Select(x => new hccCartItem
                    {
                        CartItemID              = Convert.ToInt32(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();

                    motItems.AddRange(MOTCartItem.GetFromRange(alcgc));

                    var progs = cont.hcc_OrderFulfillSearch_Programs_ByRange(startDate, endDate).ToList();
                    motItems.AddRange(MOTCartItem.GetFromRangeForMOT(progs));

                    return(motItems.OrderBy(a => a.DeliveryDate)
                           .ThenBy(a => a.ItemName).ThenBy(a => a.OrderNumber.Contains("ALC")).ThenBy(a => a.CustomerName).ToList());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }