Ejemplo n.º 1
0
        public string ResetTheProgramDefaultmenu(List <ResetMenu> resetMenuList)
        {
            string _result = string.Empty;

            try
            {
                int cartItemId = int.Parse(this.Context.Request.QueryString["cid"]);
                foreach (var resetMenu in resetMenuList)
                {
                    hccCartDefaultMenuException existMenuEx = hccCartDefaultMenuException.GetBy(resetMenu.DefaultMenuID, resetMenu.CartCalendarID);

                    if (existMenuEx != null)
                    {
                        List <hccCartDefaultMenuExPref> prefs = hccCartDefaultMenuExPref.GetBy(resetMenu.DefaultMenuExceptionId);
                        prefs.ForEach(a => a.Delete());
                        existMenuEx.Delete();
                    }
                    //hccCartMenuExPref hccCartMenuExPref = new hccCartMenuExPref()
                    //{
                    //    CartItemID = cartItemId
                    //};
                    var hccCartMenuExPrefs = hccCartMenuExPref.GetByCartItemId(cartItemId, resetMenu.DayNumber);
                    hccCartMenuExPrefs.ForEach(a => a.Delete());
                }
                _result = "Successfully reset the menu";
            }
            catch (Exception ex)
            {
                _result = "Not reset the menu";
            }
            return(_result);
        }
        List <Day> BindWeeklyGlance(List <hccProgramDefaultMenu> defaultMenuSelections, int numDaysPerWeek)
        {
            int i;

            for (i = 1; i <= numDaysPerWeek; i++)
            {
                StringBuilder sb         = new StringBuilder();
                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;

                    //hccProductionCalendar prodCal = hccProductionCalendar.GetBy(CurrentCartItem.DeliveryDate);
                    hccCartItemCalendar cartCal = hccCartItemCalendar.GetBy(this.PrimaryKeyIndex, CurrentCalendarId);

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

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

                        prefString = hccCartDefaultMenuExPref.GetPrefsBy(menuItemExc.DefaultMenuExceptID)
                                     .Select(a => a.Name).DefaultIfEmpty("None").Aggregate((a, b) => a + ", " + b);
                    }

                    if (menuItemId > 0)
                    {
                        hccMenuItem menuItem = hccMenuItem.GetById(menuItemId);

                        if (defaultSelection.MealTypeID != lastTypeId)
                        {
                            lastTypeId = defaultSelection.MealTypeID;
                            sb.Append("<span class='label'>" + ((Enums.MealTypes)lastTypeId).ToString() + "</span><br />");
                        }

                        if (menuItem != null)
                        {
                            sb.Append(menuItem.Name);
                        }

                        if (((Enums.CartItemSize)menuItemSizeId) != Enums.CartItemSize.NoSize)
                        {
                            sb.Append(" - " + Enums.GetEnumDescription(((Enums.CartItemSize)menuItemSizeId)));
                        }

                        // prefs
                        if (!string.IsNullOrWhiteSpace(prefString))
                        {
                            sb.Append(" - " + prefString);
                        }

                        try
                        {
                            var t = defaultMenuSelections[defaultMenuSelections.IndexOf(defaultSelection) + 1];
                            if (t.MealTypeID == lastTypeId)
                            {
                                sb.Append(", ");
                            }
                            else
                            {
                                sb.Append("<p></p>");
                            }
                        }
                        catch { }
                    }
                    else
                    {
                        sb.Append("<p></p>");
                    }
                });

                days.Add(new Day {
                    DayTitle = "Day: " + i.ToString(), DayNumber = i, DayInfo = sb.ToString().Trim().TrimEnd(',')
                });
            }

            lvwWeekGlance.DataSource = days;
            lvwWeekGlance.DataBind();

            return(days);
        }
        void BindForm()
        {
            if (defaultMenuSelections.Count == 0)
            {
                defaultMenuSelections = hccProgramDefaultMenu.GetBy(CurrentCalendarId, CurrentProgramId);
            }

            List <DropDownList>       ddls         = new List <DropDownList>();
            List <HtmlGenericControl> divDdls      = new List <HtmlGenericControl>();
            DailyNutrition            totalNutInfo = new DailyNutrition {
                DayNumber = CurrentDay
            };
            List <HtmlGenericControl> divItemContainers;
            string             ddlBorderClass = string.Empty;
            List <hccAllergen> userAllergens;

            userAllergens = hccUserProfileAllergen.GetAllergensBy(CurrentCartItem.UserProfile.UserProfileID, true);

            BindDropDownLists(userAllergens);

            divItemContainers =
                pnlDefaultMenu.Controls.OfType <HtmlGenericControl>().Where(a => a.Attributes["class"] == "divItemContainer").ToList();

            divItemContainers.ForEach(delegate(HtmlGenericControl ctrl)
                                      { divDdls.AddRange(ctrl.Controls.OfType <HtmlGenericControl>().Where(a => a.Attributes["class"] == "divDdl")); });

            divDdls.ForEach(a => ddls.AddRange(a.Controls.OfType <DropDownList>()));

            int dailyDefaultsCount = defaultMenuSelections.Where(a => a.DayNumber == CurrentDay).Count();

            if (dailyDefaultsCount == 0 || dailyDefaultsCount != ddls.Count)
            {
                lblFeedback.Text      += "Not all default values have been created for the selected date and program combination. Select the default items on the Production Management -> Program Default Menus page, and press 'Save' to create the default items.";
                pnlDefaultMenu.Visible = false;
            }
            else
            {
                hccCartItemCalendar cartCalendar = hccCartItemCalendar.GetBy(this.PrimaryKeyIndex, CurrentCalendarId);

                defaultMenuSelections.ForEach(delegate(hccProgramDefaultMenu defaultSelection)
                {
                    try
                    {
                        DropDownList ddl = ddls.Where(a => a.Attributes["day"] == defaultSelection.DayNumber.ToString() &&
                                                      a.Attributes["type"] == defaultSelection.MealTypeID.ToString() &&
                                                      a.Attributes["ord"] == defaultSelection.Ordinal.ToString())
                                           .SingleOrDefault();

                        if (ddl != null)
                        {
                            int menuItemId          = defaultSelection.MenuItemID;
                            string value            = menuItemId.ToString() + "-" + defaultSelection.MenuItemSizeID.ToString();
                            int DefaultMenuExceptID = 0;
                            int cartcalendarid      = 0;
                            // bold face the default selection
                            int defaultIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(value));
                            ddl.Items[(defaultIndex <= -1 ? 0 : defaultIndex)].Attributes["class"] += "bold italic";

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

                            if (menuItemExc != null)
                            {
                                menuItemId          = menuItemExc.MenuItemID;
                                value               = menuItemId.ToString() + "-" + menuItemExc.MenuItemSizeID.ToString();
                                DefaultMenuExceptID = menuItemExc.DefaultMenuExceptID;
                                cartcalendarid      = menuItemExc.CartCalendarID;
                            }

                            ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(value));
                            ddl.Attributes.Add("defMenuId", defaultSelection.DefaultMenuID.ToString());
                            ddl.Attributes.Add("defMenuExceptionId", DefaultMenuExceptID.ToString());
                            ddl.Attributes.Add("defMenuCartCalendarId", cartcalendarid.ToString());
                            ddl.SelectedItem.Attributes["class"] += " bold";

                            HtmlGenericControl divItemContainer = (HtmlGenericControl)ddl.Parent.Parent;
                            HtmlGenericControl divNuts          =
                                divItemContainer.Controls.OfType <HtmlGenericControl>().Where(a => a.Attributes["class"] == "divNuts").SingleOrDefault();
                            HtmlGenericControl divAllrgs =
                                divItemContainer.Controls.OfType <HtmlGenericControl>().Where(a => a.Attributes["class"] == "divAllrgs").SingleOrDefault();
                            HtmlGenericControl divPrefs =
                                divItemContainer.Controls.OfType <HtmlGenericControl>().Where(a => a.Attributes["class"] == "divPrefs").SingleOrDefault();

                            if (menuItemId > 0)
                            {
                                hccMenuItem menuItem = null;

                                if (menuItemExc == null)
                                {
                                    if (defaultSelection.MenuItemID > 0)
                                    {
                                        menuItem = hccMenuItem.GetById(defaultSelection.MenuItemID);
                                    }
                                }
                                else if (menuItemExc.MenuItemID > 0)
                                {
                                    menuItem = hccMenuItem.GetById(menuItemExc.MenuItemID);
                                }

                                if (menuItem != null)
                                {
                                    // nutrition info
                                    if (divNuts != null)
                                    {
                                        string nutInfo = string.Empty;
                                        hccMenuItemNutritionData menuNut = hccMenuItemNutritionData.GetBy(menuItem.MenuItemID);

                                        if (menuNut != null)
                                        {
                                            nutInfo = string.Format("Calories: {0}, Fat: {1}, Protein: {2},  Carbohydrates: {3}, Fiber: {4},Sodium: {5}",
                                                                    menuNut.Calories.ToString("f2"), menuNut.TotalFat.ToString("f2"), menuNut.Protein.ToString("f2"),
                                                                    menuNut.TotalCarbohydrates.ToString("f2"), menuNut.DietaryFiber.ToString("f2"), menuNut.Sodium.ToString("f2"));
                                            divNuts.InnerHtml      = nutInfo;
                                            totalNutInfo.Calories += menuNut.Calories;
                                            totalNutInfo.Carbs    += menuNut.TotalCarbohydrates;
                                            totalNutInfo.Fat      += menuNut.TotalFat;
                                            totalNutInfo.Fiber    += menuNut.DietaryFiber;
                                            totalNutInfo.Protein  += menuNut.Protein;
                                            totalNutInfo.Sodium   += menuNut.Sodium;
                                        }
                                        else
                                        {
                                            nutInfo = string.Format("Calories: {0}, Fat: {1}, Protein: {2},  Carbohydrates: {3}, Fiber: {4},Sodium: {5}", 0, 0, 0, 0, 0, 0);
                                        }

                                        divNuts.InnerText = nutInfo;
                                    }

                                    // allergen displays
                                    List <hccAllergen> selectItemAllergens = new List <hccAllergen>();
                                    string allrgsList   = string.Empty;
                                    allrgsList          = "Allergens: " + menuItem.AllergensList;
                                    selectItemAllergens = menuItem.GetAllergens();

                                    if (divAllrgs != null)
                                    {
                                        divAllrgs.InnerText = allrgsList;
                                    }

                                    List <hccAllergen> matchedAllergens = selectItemAllergens.Intersect(userAllergens).ToList();

                                    if (matchedAllergens.Count > 0)
                                    {
                                        ddl.SelectedItem.Attributes["class"] += " bold";
                                        ddlBorderClass = "redBorder";
                                    }
                                    else
                                    {
                                        if (menuItemExc == null)
                                        {
                                            ddlBorderClass = "greenBorder";
                                        }
                                        else
                                        {
                                            ddlBorderClass = "blueBorder";
                                        }
                                    }

                                    // preferences
                                    List <hccPreference> itemPrefs = menuItem.GetPreferences();

                                    if (itemPrefs.Count > 0 && divPrefs != null)
                                    {
                                        itemPrefs.ForEach(delegate(hccPreference pref)
                                        {
                                            HtmlInputCheckBox chkPref = new HtmlInputCheckBox();
                                            chkPref.Value             = pref.PreferenceID.ToString();
                                            Label lblPref             = new Label();
                                            lblPref.Text = pref.Name;

                                            divPrefs.Controls.Add(chkPref);
                                            divPrefs.Controls.Add(lblPref);

                                            hccCartMenuExPref cartMenuExPref = hccCartMenuExPref.GetById(cartCalendar.CartItemID, defaultSelection.DayNumber);

                                            if (cartMenuExPref != null)
                                            {
                                                if (cartMenuExPref.IsModified)
                                                {
                                                    if (menuItemExc != null)
                                                    {
                                                        hccCartDefaultMenuExPref excPref = hccCartDefaultMenuExPref.GetBy(menuItemExc.DefaultMenuExceptID, pref.PreferenceID);
                                                        if (excPref != null)
                                                        {
                                                            chkPref.Checked = true;
                                                        }
                                                    }
                                                }
                                                //hccCartItem cartItem = hccCartItem.GetById(cartCalendar.CartItemID);
                                                //if (cartItem != null)
                                                //{
                                                //    if (Convert.ToBoolean(cartItem.IsModified))
                                                //    {
                                                //        hccCartDefaultMenuExPref excPref = hccCartDefaultMenuExPref.GetBy(menuItemExc.DefaultMenuExceptID, pref.PreferenceID);
                                                //        if (excPref != null)
                                                //        {
                                                //            chkPref.Checked = true;
                                                //        }
                                                //    }
                                                //    else
                                                //    {
                                                //        hccCartDefaultMenuExPref excPref = hccCartDefaultMenuExPref.GetBy(menuItemExc.DefaultMenuExceptID, pref.PreferenceID);
                                                //        if (excPref != null)
                                                //            chkPref.Checked = true;
                                                //        hccProgramDefaultMenuExPref programmenuexpref = hccProgramDefaultMenuExPref.GetBy(defaultSelection.DefaultMenuID, pref.PreferenceID);
                                                //        if (programmenuexpref != null)
                                                //            chkPref.Checked = true;
                                                //    }
                                                //}
                                            }
                                            else
                                            {
                                                //hccCartItem cartItem = hccCartItem.GetById(cartCalendar.CartItemID);
                                                //if (cartItem != null)
                                                //{
                                                //    if (!Convert.ToBoolean(cartItem.IsModified))
                                                //    {
                                                //        hccProgramDefaultMenuExPref programmenuexpref = hccProgramDefaultMenuExPref.GetBy(defaultSelection.DefaultMenuID, pref.PreferenceID);
                                                //        if (programmenuexpref != null)
                                                //            chkPref.Checked = true;
                                                //    }
                                                //}
                                                hccProgramDefaultMenuExPref programmenuexpref = hccProgramDefaultMenuExPref.GetBy(defaultSelection.DefaultMenuID, pref.PreferenceID);
                                                if (programmenuexpref != null)
                                                {
                                                    chkPref.Checked = true;
                                                }
                                            }
                                        });
                                    }
                                }
                                else
                                {
                                    divNuts.InnerText   = string.Empty;
                                    divPrefs.InnerText  = string.Empty;
                                    divAllrgs.InnerText = string.Empty;
                                }
                                ddl.CssClass = "mealItemDdl " + ddlBorderClass;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                });

                if (totalNutInfo == null)
                {
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Cals##", "0");
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Fats##", "0");
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Ptrns##", "0");
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Carbs##", "0");
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Fbrs##", "0");
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Sod##", "0");
                }
                else
                {
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Cals##", totalNutInfo.Calories.ToString("f2"));
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Fats##", totalNutInfo.Fat.ToString("f2"));
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Ptrns##", totalNutInfo.Protein.ToString("f2"));
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Carbs##", totalNutInfo.Carbs.ToString("f2"));
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Fbrs##", totalNutInfo.Fiber.ToString("f2"));
                    divTotalNutrition.InnerHtml = divTotalNutrition.InnerHtml.Replace("##Sod##", totalNutInfo.Sodium.ToString("f2"));
                }

                divTotalNutrition.Visible = true;
            }
        }
Ejemplo n.º 4
0
        public string ReplaceProgramMeals(List <DefaultMenu> defaultMenus)
        {
            try
            {
                bool tryBool;
                bool isCancel   = false;
                bool isComplete = false;
                int  cartItemId = int.Parse(this.Context.Request.QueryString["cid"]);

                hccCartItem cartItem = hccCartItem.GetById(cartItemId);
                if (cartItem != null)
                {
                    if (this.Context.Request.QueryString["can"] != null)
                    {
                        tryBool = bool.TryParse(this.Context.Request.QueryString["can"], out isCancel);
                        cartItem.IsCancelled = isCancel;
                    }

                    if (this.Context.Request.QueryString["cmplt"] != null)
                    {
                        tryBool = bool.TryParse(this.Context.Request.QueryString["cmplt"], out isComplete);
                    }
                    hccCartMenuExPref cartMenuExPref = hccCartMenuExPref.GetById(cartItem.CartItemID, defaultMenus[0].DayNumber);
                    if (cartMenuExPref == null)
                    {
                        hccCartMenuExPref hccCartMenuExPref = new hccCartMenuExPref();
                        hccCartMenuExPref.CartItemID = cartItem.CartItemID;
                        hccCartMenuExPref.DayNumber  = defaultMenus[0].DayNumber;
                        hccCartMenuExPref.IsModified = true;
                        hccCartMenuExPref.Save();
                    }
                    cartItem.Save();
                }

                decimal cals1 = 0.0m, fat1 = 0.0m, prtn1 = 0.0m, carb1 = 0.0m, fbr1 = 0.0m, sod1 = 0.0m;

                foreach (DefaultMenu defaultMenuItem in defaultMenus)
                {
                    hccCartItemCalendar cartCal = hccCartItemCalendar.GetBy(cartItem.CartItemID, defaultMenuItem.CalendarID);

                    if (cartCal != null)
                    {
                        if (isComplete != cartCal.IsFulfilled)
                        {
                            cartCal.IsFulfilled = isComplete;
                            cartCal.Save();
                        }

                        // get original defaultMenuItem for comparison of menuItem
                        hccProgramDefaultMenu origDefaultMenu =
                            hccProgramDefaultMenu.GetBy(cartCal.CalendarID, defaultMenuItem.ProgramID,
                                                        defaultMenuItem.DayNumber, defaultMenuItem.MealTypeID, defaultMenuItem.Ordinal);

                        hccCartDefaultMenuException existMenuEx = hccCartDefaultMenuException.GetBy(defaultMenuItem.DefaultMenuID, cartCal.CartCalendarID);

                        if (origDefaultMenu != null &&
                            origDefaultMenu.MenuItemID == defaultMenuItem.MenuItemID &&
                            origDefaultMenu.MenuItemSizeID == defaultMenuItem.MenuItemSizeID)
                        {
                            if (string.IsNullOrWhiteSpace(defaultMenuItem.Prefs))
                            {
                                if (existMenuEx != null)
                                {
                                    List <hccCartDefaultMenuExPref> prefs = hccCartDefaultMenuExPref.GetBy(existMenuEx.DefaultMenuExceptID);
                                    prefs.ForEach(a => a.Delete());
                                    existMenuEx.Delete();
                                }
                            }
                            else
                            {
                                if (existMenuEx == null)
                                {   // create exception menuItem
                                    existMenuEx = new hccCartDefaultMenuException
                                    {
                                        CartCalendarID = cartCal.CartCalendarID,
                                        DefaultMenuID  = defaultMenuItem.DefaultMenuID
                                    };
                                }

                                existMenuEx.MenuItemID     = defaultMenuItem.MenuItemID;
                                existMenuEx.MenuItemSizeID = defaultMenuItem.MenuItemSizeID;
                                existMenuEx.Save();

                                List <hccCartDefaultMenuExPref> prefs = hccCartDefaultMenuExPref.GetBy(existMenuEx.DefaultMenuExceptID);
                                prefs.ForEach(a => a.Delete());

                                if (!string.IsNullOrWhiteSpace(defaultMenuItem.Prefs))
                                {
                                    List <string> prefIds = defaultMenuItem.Prefs.Split(',').ToList();
                                    prefIds.ForEach(delegate(string prefId)
                                    {
                                        hccCartDefaultMenuExPref exPref = new hccCartDefaultMenuExPref
                                        {
                                            DefaultMenuExceptID = existMenuEx.DefaultMenuExceptID,
                                            PreferenceID        = int.Parse(prefId)
                                        };

                                        exPref.Save();
                                    });
                                }
                            }
                        }
                        else
                        {
                            if (existMenuEx == null)
                            {   // create exception menuItem
                                existMenuEx = new hccCartDefaultMenuException
                                {
                                    CartCalendarID = cartCal.CartCalendarID,
                                    DefaultMenuID  = defaultMenuItem.DefaultMenuID
                                };
                            }

                            existMenuEx.MenuItemID     = defaultMenuItem.MenuItemID;
                            existMenuEx.MenuItemSizeID = defaultMenuItem.MenuItemSizeID;
                            existMenuEx.Save();

                            List <hccCartDefaultMenuExPref> exPrefs = hccCartDefaultMenuExPref.GetBy(existMenuEx.DefaultMenuExceptID);
                            exPrefs.ForEach(a => a.Delete());

                            if (!string.IsNullOrWhiteSpace(defaultMenuItem.Prefs))
                            {
                                List <string> prefIds = defaultMenuItem.Prefs.Split(',').ToList();
                                prefIds.ForEach(delegate(string prefId)
                                {
                                    hccCartDefaultMenuExPref exPref = new hccCartDefaultMenuExPref
                                    {
                                        DefaultMenuExceptID = existMenuEx.DefaultMenuExceptID,
                                        PreferenceID        = int.Parse(prefId)
                                    };

                                    exPref.Save();
                                });
                            }
                        }

                        hccMenuItemNutritionData nutrition;

                        if (existMenuEx == null)
                        {
                            nutrition = hccMenuItemNutritionData.GetBy(defaultMenuItem.MenuItemID);
                        }
                        else
                        {
                            nutrition = hccMenuItemNutritionData.GetBy(existMenuEx.MenuItemID);
                        }

                        if (nutrition != null)
                        {
                            cals1 = cals1 + nutrition.Calories;
                            fat1  = fat1 + nutrition.TotalFat;
                            prtn1 = prtn1 + nutrition.Protein;
                            carb1 = carb1 + nutrition.TotalCarbohydrates;
                            fbr1  = fbr1 + nutrition.DietaryFiber;
                            sod1  = sod1 + nutrition.Sodium;
                        }
                    }
                }

                string nutri = cals1.ToString("f2") + "|" + fat1.ToString("f2") + "|" + prtn1.ToString("f2") + "|" + carb1.ToString("f2") + "|" + fbr1.ToString("f2") + "|" + sod1.ToString("f2");

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