public Tuple <string, DateTime> GetNameAndDateAndMenuItems(hccCartItem cartItem, hccCartItemCalendar cartCalendar) //, out List<hccMenuItem> menuItems)
        {
            string   newName = cartItem.SimpleName;
            DateTime?delDate = null;
            Tuple <string, DateTime> retVal = null;

            try
            {
                hccProductionCalendar prodCal = hccProductionCalendar.GetById(cartCalendar.CalendarID);

                if (prodCal != null)
                {
                    hccProgramPlan             plan     = hccProgramPlan.GetById(cartItem.Plan_PlanID.Value);
                    List <hccCartItemCalendar> cartCals = hccCartItemCalendar.GetByCartItemID(cartItem.CartItemID);
                    hccCartItemCalendar        cartCal  = cartCals.Where(a => a.CalendarID == prodCal.CalendarID).SingleOrDefault();

                    if (cartCal != null)
                    {
                        int cartCalIndex = cartCals.IndexOf(cartCal);

                        newName += " - Week: " + (cartCalIndex + 1).ToString();
                        delDate  = prodCal.DeliveryDate;
                    }
                }
            }
            catch { throw; }

            if (delDate.HasValue)
            {
                retVal = new Tuple <string, DateTime>(newName, delDate.Value);
            }

            return(retVal);
        }
        public void Delete()
        {
            try
            {
                using (var cont = new healthychefEntities())
                {
                    System.Data.EntityKey key = cont.CreateEntityKey("hccCartItemCalendars", this);
                    object originalItem       = null;

                    if (cont.TryGetObjectByKey(key, out originalItem))
                    {
                        hccCartItemCalendar item = cont.hccCartItemCalendars
                                                   .Where(a => a.CartCalendarID == this.CartCalendarID).SingleOrDefault();

                        if (item != null)
                        {
                            cont.hccCartItemCalendars.DeleteObject(item);
                            cont.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public AggrCartItem(hccCartItemCalendar cartCalendar, bool includeSnapshot)
            : this()
        {
            try
            {
                CartItem = hccCartItem.GetById(cartCalendar.CartItemID);

                if (includeSnapshot)
                {
                    CartSnap = hccCartSnapshot.GetBy(CartItem.CartID);
                }

                CartItemId    = CartItem.CartItemID;
                TotalQuantity = CartItem.Quantity;

                var t = GetNameAndDateAndMenuItems(CartItem, cartCalendar);

                if (t != null)
                {
                    SimpleName   = t.Item1;
                    DeliveryDate = t.Item2;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #4
0
 public MOTCartItem(hccCartItemCalendar cartCalendar)
 {
     try
     {
         CartItem   = hccCartItem.GetById(cartCalendar.CartItemID);
         CartItemId = CartItem.CartItemID;
     }
     catch (Exception)
     {
         throw;
     }
 }
        public List <int> GetDaysWithAllergens(int cartCalendarId)
        {
            try
            {
                List <int>          daysWithAllergens = new List <int>();
                hccProgramPlan      plan    = hccProgramPlan.GetById(this.Plan_PlanID.Value);
                hccUserProfile      profile = hccUserProfile.GetById(this.UserProfileID);
                hccCartItemCalendar cartCal = hccCartItemCalendar.GetById(cartCalendarId);

                if (plan != null && profile != null)
                {
                    // get list of user profile allergens
                    List <hccAllergen> userAllergens = profile.GetAllergens();

                    if (userAllergens.Count > 0)
                    {
                        List <hccProgramDefaultMenu> defaultMenus = hccProgramDefaultMenu.GetBy(cartCal.CalendarID, plan.ProgramID);

                        defaultMenus.ForEach(delegate(hccProgramDefaultMenu defaultMenu)
                        {
                            hccCartDefaultMenuException excMenu = hccCartDefaultMenuException.GetBy(defaultMenu.DefaultMenuID, cartCal.CartCalendarID);
                            List <hccAllergen> menuAllg         = new List <hccAllergen>();

                            if (excMenu == null)
                            {
                                hccMenuItem item = hccMenuItem.GetById(defaultMenu.MenuItemID);
                                if (item != null)
                                {
                                    menuAllg = item.GetAllergens();
                                }
                            }
                            else
                            {
                                menuAllg = excMenu.GetMenuItemAllergens();
                            }

                            if (menuAllg.Count > 0)
                            {
                                if (userAllergens.Intersect(menuAllg).Count() > 0)
                                {
                                    daysWithAllergens.Add(defaultMenu.DayNumber);
                                }
                            }
                        });
                    }
                }
                return(daysWithAllergens);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public hccCartItemCalendar GetNextCartCalendar(DayOfWeek requiredDayOfWeek)
        {
            try
            {
                hccProductionCalendar prodCal     = hccProductionCalendar.GetById(this.CalendarID);
                DateTime nextDeliveryDate         = prodCal.DeliveryDate.AddDays(7);
                hccProductionCalendar nextProdCal = hccProductionCalendar.GetBy(nextDeliveryDate);
                int calendarId = 0;

                if (nextProdCal == null)
                {
                    nextProdCal = new DAL.hccProductionCalendar
                    {
                        DeliveryDate    = nextDeliveryDate,
                        Name            = "Delivery Date " + nextDeliveryDate.ToShortDateString(),
                        OrderCutOffDate = nextDeliveryDate.AddDays(-8)
                    };
                    calendarId = nextProdCal.Save();
                }
                else
                {
                    calendarId = nextProdCal.CalendarID;
                }

                var nextCartCalendar = hccCartItemCalendar.GetBy(this.CartItemID, calendarId);

                if (nextCartCalendar == null)
                {
                    nextCartCalendar = new hccCartItemCalendar {
                        CalendarID = calendarId, CartItemID = this.CartItemID
                    };
                    nextCartCalendar.Save();
                    return(nextCartCalendar);
                }
                else
                {
                    throw new Exception("hccCartItemCalendar - nextCartCalendar was expected to be null");
                }
            }
            catch
            {
                throw;
            }
        }
예제 #7
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);
        }
예제 #8
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;
            }
        }
예제 #9
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);
        }
예제 #10
0
        public static List <ChefProdItem> GetPackSlipItems(string orderNumber, DateTime deliveryDate)
        {
            try
            {
                List <MealItemReportItem> results  = null;
                List <ChefProdItem>       retItems = new List <ChefProdItem>();

                results = ReportSprocs.GetMenuItemsByOrderNumber(orderNumber, deliveryDate).ToList();
                results = results.Where(ri => !hccMenuItem.SideMealTypes.Contains((Enums.MealTypes)ri.MealTypeId)).ToList();

                var cartItems = hccCartItem.GetByIds(results.Select(i => i.CartItemId).ToList());

                if (results != null && results.Count > 0)
                {
                    foreach (MealItemReportItem result in results)
                    {
                        if (result.MealSizeId == 0)
                        {
                            result.MealSizeId = 3; // update noSize to regular size
                        }
                        var cartItem = cartItems.FirstOrDefault(i => i.CartItemID == result.CartItemId);

                        if (cartItem == null)
                        {
                            continue; // should not happen
                        }
                        var newItem = new ChefProdItem
                        {
                            ParentTypeId = result.ParentTypeId,
                            ParentId     = result.ParentId,
                            MenuItemId   = result.MenuItemId,
                            MealTypeId   = result.MealTypeId,
                            MealSizeId   = result.MealSizeId,
                            ItemName     = result.ItemName, // + "-" + result.OrderNumber + " - " + result.ParentTypeId + "-" + result.ParentId,
                            MealType     = Enums.GetEnumDescription(((Enums.MealTypes)result.MealTypeId)),
                            MealSize     = Enums.GetEnumDescription(((Enums.CartItemSize)result.MealSizeId)),
                            Quantity     = result.Quantity,
                            DeliveryDate = result.DeliveryDate,
                            OrderNumber  = result.OrderNumber,
                            DayNumber    = result.DayNum,
                            Prefs        = string.IsNullOrWhiteSpace(result.Prefs) ? "" : result.Prefs,
                            CartItemId   = result.CartItemId,
                            CartItemType = Enums.GetEnumDescription(((Enums.CartItemTypeAbbr)cartItem.ItemTypeID))
                        };

                        if (cartItem.ItemTypeID == Convert.ToInt32((Enums.CartItemType.AlaCarte)) && cartItem.Plan_IsAutoRenew == true)
                        {
                            newItem.IsFamilyStyle = "Yes";
                        }
                        else if (cartItem.ItemTypeID == Convert.ToInt32((Enums.CartItemType.AlaCarte)) && cartItem.Plan_IsAutoRenew == false)
                        {
                            newItem.IsFamilyStyle = "No";
                        }
                        else
                        {
                            newItem.IsFamilyStyle = "N/A";
                        }
                        hccUserProfile prof = hccUserProfile
                                              .GetById(result.UserProfileId);

                        if (prof != null)
                        {
                            newItem.UserName    = prof.ParentProfileName;
                            newItem.ProfileName = prof.ProfileName;
                        }

                        hccCartItemCalendar cartCal = hccCartItemCalendar.GetBy(newItem.CartItemId, newItem.DeliveryDate);

                        if (newItem.ParentTypeId == 1) //a la carte
                        {
                            newItem.Sides = cartItem.GetMealSideMenuItemsAsSectionString(", ");
                            newItem.Side1 = cartItem.GetMealSide1MenuItemName();
                            newItem.Side2 = cartItem.GetMealSide2MenuItemName();
                            retItems.Add(newItem);
                        }
                        else //is program plan
                        {
                            Enums.MealTypes mealType = (Enums.MealTypes)result.MealTypeId;

                            if (mealType == Enums.MealTypes.BreakfastEntree ||
                                mealType == Enums.MealTypes.LunchEntree ||
                                mealType == Enums.MealTypes.DinnerEntree ||
                                mealType == Enums.MealTypes.OtherEntree ||
                                mealType == Enums.MealTypes.ChildEntree ||
                                mealType == Enums.MealTypes.Beverage ||
                                mealType == Enums.MealTypes.Dessert ||
                                mealType == Enums.MealTypes.Goods ||
                                mealType == Enums.MealTypes.Miscellaneous ||
                                mealType == Enums.MealTypes.Salad ||
                                mealType == Enums.MealTypes.Snack ||
                                mealType == Enums.MealTypes.Soup ||
                                mealType == Enums.MealTypes.Supplement)    // Non-Side Types
                            {
                                hccProgramDefaultMenu        defMenu = null;
                                List <hccProgramDefaultMenu> defMenus;

                                if (newItem.ParentTypeId == 2) //plan with exception
                                {
                                    hccCartDefaultMenuException defEx = hccCartDefaultMenuException.GetById(newItem.ParentId);

                                    if (defEx != null)
                                    {
                                        defMenu = hccProgramDefaultMenu.GetById(defEx.DefaultMenuID);

                                        //newItem.Prefs = hccCartDefaultMenuExPref.GetPrefsBy(defEx.DefaultMenuExceptID)
                                        //    .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d);
                                    }
                                }
                                else if (newItem.ParentTypeId == 3) //plan default
                                {
                                    defMenu       = hccProgramDefaultMenu.GetById(newItem.ParentId);
                                    newItem.Prefs = "";
                                }

                                //newItem.DayNumber = defMenu.DayNumber;
                                if (defMenu == null)
                                {
                                    retItems.Add(newItem);
                                    continue;
                                }

                                defMenus = hccProgramDefaultMenu.GetBy(defMenu.CalendarID, defMenu.ProgramID);

                                //cheat to find related sides
                                List <hccProgramDefaultMenu> sides = new List <hccProgramDefaultMenu>();
                                string sideStr = string.Empty;

                                if (newItem.MealTypeId < 100)
                                {
                                    sides = defMenus.Where(a => a.DayNumber == newItem.DayNumber && (a.MealTypeID == (newItem.MealTypeId + 10))).ToList();
                                }

                                sides.ForEach(delegate(hccProgramDefaultMenu sideDefMenu)
                                {
                                    hccCartDefaultMenuException sideEx = hccCartDefaultMenuException.GetBy(sideDefMenu.DefaultMenuID, cartCal.CartCalendarID);
                                    hccMenuItem sideItem;
                                    Enums.CartItemSize sidePortionSize;
                                    string prefsString = string.Empty;

                                    if (sideEx == null)
                                    {
                                        sideItem        = hccMenuItem.GetById(sideDefMenu.MenuItemID);
                                        sidePortionSize = (Enums.CartItemSize)sideDefMenu.MenuItemSizeID;
                                        prefsString     = string.Empty;
                                    }
                                    else
                                    {
                                        sideItem        = hccMenuItem.GetById(sideEx.MenuItemID);
                                        sidePortionSize = (Enums.CartItemSize)defMenu.MenuItemSizeID;
                                        prefsString     = hccCartDefaultMenuExPref.GetPrefsBy(sideEx.DefaultMenuExceptID)
                                                          .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((c, d) => c + ", " + d);
                                    }

                                    if (sideItem != null)
                                    {
                                        switch (sideDefMenu.Ordinal)
                                        {
                                        case 1:
                                            {
                                                newItem.Side1 = sideItem.Name;
                                                if (!string.IsNullOrWhiteSpace(prefsString))
                                                {
                                                    newItem.Side1 += " - " + prefsString;
                                                }
                                                break;
                                            }

                                        case 2:
                                            {
                                                newItem.Side2 = sideItem.Name;
                                                if (!string.IsNullOrWhiteSpace(prefsString))
                                                {
                                                    newItem.Side2 += " - " + prefsString;
                                                }
                                                break;
                                            }

                                        default:
                                            {
                                                // not supported side
                                                break;
                                            }
                                        }
                                    }

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

                                    if (string.IsNullOrWhiteSpace(sideStr))
                                    {
                                        if (sideItem != null)
                                        {
                                            sideStr = sideItem.Name;
                                        }

                                        //sideStr += " - " + sidePortionSize.ToString();

                                        if (!string.IsNullOrWhiteSpace(prefsString))
                                        {
                                            sideStr += " - " + prefsString;
                                        }
                                    }
                                    else
                                    {
                                        if (sideItem != null)
                                        {
                                            sideStr += ", " + sideItem.Name;
                                        }

                                        //sideStr += " - " + sidePortionSize.ToString();

                                        if (!string.IsNullOrWhiteSpace(prefsString))
                                        {
                                            sideStr += " - " + prefsString;
                                        }
                                    }
                                });

                                if (string.IsNullOrWhiteSpace(sideStr) || string.Equals(sideStr, "None", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    sideStr = string.Empty;
                                }

                                newItem.Sides = sideStr;
                                retItems.Add(newItem);
                            }
                            else // it is a side item
                            { // skip it
                            }
                        }
                    }
                }

                return(retItems);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public List <Day> BindWeeklyGlance(List <hccProgramDefaultMenu> defaultMenuSelections, int numDaysPerWeek, int cartItemId)
        {
            StringBuilder      sb    = new StringBuilder();
            List <hccMenuItem> lstMI = new List <hccMenuItem>();
            Day       d  = new Day();
            MealTypes mT = new MealTypes();

            string currentMealType = "";
            int    i, currentDay = 1;

            for (i = 1; i <= numDaysPerWeek; i++)
            {
                int lastTypeId = 0;

                defaultMenuSelections.Where(a => a.DayNumber == i)
                .OrderBy(a => a.MealTypeID).ToList().ForEach(delegate(hccProgramDefaultMenu defaultSelection)
                {
                    int menuItemId     = defaultSelection.MenuItemID;
                    int menuItemSizeId = defaultSelection.MenuItemSizeID;

                    hccCartItemCalendar cartCal = hccCartItemCalendar.GetBy(cartItemId, CurrentCalendarId);

                    hccCartDefaultMenuException menuItemExc
                        = hccCartDefaultMenuException.GetBy(defaultSelection.DefaultMenuID, cartCal.CartCalendarID);

                    if (menuItemExc != null)
                    {
                        menuItemId     = menuItemExc.MenuItemID;
                        menuItemSizeId = menuItemExc.MenuItemSizeID;

                        List <hccCartDefaultMenuExPref> prefs = hccCartDefaultMenuExPref.GetBy(menuItemExc.DefaultMenuExceptID);
                    }
                    if (menuItemId > 0)
                    {
                        hccMenuItem menuItem = hccMenuItem.GetById(menuItemId);

                        //if (defaultSelection.MealTypeID != lastTypeId)
                        //{
                        lastTypeId = defaultSelection.MealTypeID;

                        if (((Enums.MealTypes)lastTypeId).ToString().ToLower().Contains("breakfast"))
                        {
                            currentMealType = "breakfast";
                        }
                        else if (((Enums.MealTypes)lastTypeId).ToString().ToLower().Contains("lunch"))
                        {
                            currentMealType = "lunch";
                        }
                        else if (((Enums.MealTypes)lastTypeId).ToString().ToLower().Contains("dinner"))
                        {
                            currentMealType = "dinner";
                        }
                        else if (((Enums.MealTypes)lastTypeId).ToString().ToLower().Contains("dessert"))
                        {
                            currentMealType = "dessert";
                        }
                        else if (((Enums.MealTypes)lastTypeId).ToString().ToLower().Contains("snack"))
                        {
                            currentMealType = "snack";
                        }

                        if (mT.MealType != currentMealType && mT.MealType != null)
                        {
                            if (sb.ToString().EndsWith(",<br />") == true)
                            {
                                mT.MealInfo = sb.ToString().Substring(0, sb.ToString().Length - 7);
                            }
                            //mT.MealInfo = sb.ToString().Trim().TrimEnd(',');

                            d.MealTypes.Add(mT);

                            mT = new MealTypes();
                            sb = new StringBuilder();
                        }

                        mT.MealType = currentMealType;

                        if (menuItem != null)
                        {
                            sb.Append(menuItem.Name);
                            sb.Append(",<br />");
                        }

                        /*if (((Enums.CartItemSize)menuItemSizeId) != Enums.CartItemSize.NoSize)
                         * {
                         *  sb.Append(" - " + Enums.GetEnumDescription(((Enums.CartItemSize)menuItemSizeId)));
                         *  sb.Append(", ");
                         * } */
                        if (currentDay != defaultSelection.DayNumber)         // only create a new day when daynumber changes
                        {
                            sb.ToString().Trim().TrimEnd(',');
                            d.DayTitle = currentDay.ToString();
                            //d.DayTitle = "Day: " + currentDay.ToString();
                            d.DayNumber = currentDay;
                            days.Add(d);
                            d          = new Day();
                            currentDay = defaultSelection.DayNumber;
                        }
                        //}
                        menuItemId = 0;
                    }
                });
            }
            if (sb.ToString().EndsWith(",<br />") == true)
            {
                mT.MealInfo = sb.ToString().Substring(0, sb.ToString().Length - 7);
            }
            //mT.MealInfo = sb.ToString().Trim().TrimEnd(',');
            d.MealTypes.Add(mT);
            d.DayTitle = currentDay.ToString();
            //d.DayTitle = "Day: " + currentDay.ToString();
            d.DayNumber = currentDay;
            days.Add(d);

            return(days);
        }