public static void DeleteDuplicates()
        {
            try
            {
                List <hccProgramDefaultMenu> defMenus    = GetAll();
                hccProgramDefaultMenu        lastDefMenu = null;
                List <int> deleteIDs = new List <int>();

                foreach (hccProgramDefaultMenu curDefMenu in defMenus)
                {
                    if (!curDefMenu.IsDuplicateOf(lastDefMenu))
                    {
                        lastDefMenu = curDefMenu;
                    }
                    else
                    {
                        if (lastDefMenu.MenuItemID == 0 && curDefMenu.MenuItemID > 0)
                        {
                            deleteIDs.Add(lastDefMenu.DefaultMenuID);
                            lastDefMenu = curDefMenu;
                        }
                        else
                        {
                            deleteIDs.Add(curDefMenu.DefaultMenuID);
                        }
                    }
                }

                foreach (int id in deleteIDs)
                {
                    hccProgramDefaultMenu defMenu = hccProgramDefaultMenu.GetById(id);
                    defMenu.Delete();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 bool IsDuplicateOf(hccProgramDefaultMenu otherDefMenu)
 {
     if (otherDefMenu == null)
     {
         return(false);
     }
     else
     {
         if (this.CalendarID == otherDefMenu.CalendarID &&
             this.ProgramID == otherDefMenu.ProgramID &&
             this.DayNumber == otherDefMenu.DayNumber &&
             this.MealTypeID == otherDefMenu.MealTypeID &&
             this.Ordinal == otherDefMenu.Ordinal)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
        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;
            }
        }