Exemplo n.º 1
0
    private void BuildTree(MCategory[] cats, int?parentCategoryId, TreeNode rootNode)
    {
        Menu menu = this.CurrentMenu;

        var list = cats.Where(mc => mc.ParentMCategoryId == parentCategoryId);

        foreach (MCategory item in list)
        {
            TreeNode node = new TreeNode(item.MCategoryName, item.MCategoryId.ToString());
            if (menu.MCategories != null &&
                menu.MCategories.SingleOrDefault(mc => mc.MCategoryId == item.MCategoryId) != null)
            {
                node.Checked = true;
            }

            if (rootNode == null)
            {
                this.tvCategories.Nodes.Add(node);
            }
            else
            {
                rootNode.ChildNodes.Add(node);
            }

            BuildTree(cats, item.MCategoryId, node);
        }
    }
Exemplo n.º 2
0
    protected void rptRecipes_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        Menu menu = this.CurrentMenu;

        Meal       meal = null;
        MealRecipe currentMealRecipe = e.Item.DataItem as MealRecipe;

        if (currentMealRecipe != null)
        {
            meal = currentMealRecipe.Meal;
        }

        LinkButton lnkBtn = e.Item.FindControl("removeFromMeal") as LinkButton;

        if (lnkBtn != null)
        {
            lnkBtn.Attributes["recipeId"]      = currentMealRecipe.RecipeId.ToString();
            lnkBtn.Attributes["mealSignature"] = this.GetMealSignature(meal);
        }

        TextBox txtBox = e.Item.FindControl("txtServings") as TextBox;

        if (txtBox != null)
        {
            txtBox.Attributes["recipeId"]      = currentMealRecipe.RecipeId.ToString();
            txtBox.Attributes["mealSignature"] = this.GetMealSignature(meal);
        }
    }
Exemplo n.º 3
0
    protected void txtDinersNum_TextChanged(object sender, EventArgs e)
    {
        Menu    menu = this.CurrentMenu;
        int     dinersNumber;
        TextBox txtDinersNum = sender as TextBox;

        if (txtDinersNum != null && int.TryParse(txtDinersNum.Text, out dinersNumber))
        {
            Meal  mealToChange    = null;
            int[] mealIdentifiers = GetMealIdentifiers(txtDinersNum.Attributes["mealSignature"]);

            if (menu.MenuTypeId == (int)MenuTypeEnum.QuickMenu)
            {
                mealToChange = menu.Meals.SingleOrDefault(me => me.MealTypeId == mealIdentifiers[1]);
            }
            if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal)
            {
                mealToChange = menu.Meals.SingleOrDefault(me => me.CourseTypeId == mealIdentifiers[2]);
            }
            else
            {
                mealToChange = menu.Meals.SingleOrDefault(me => me.DayIndex == mealIdentifiers[0] && me.MealTypeId == mealIdentifiers[1]);
            }

            if (mealToChange != null)
            {
                mealToChange.Diners = dinersNumber;
            }
        }
    }
Exemplo n.º 4
0
    protected void NewMenu()
    {
        Menu menu = new Menu();

        Dictionary <int, Recipe> selectedRecipes = Utils.SelectedRecipes;

        if (selectedRecipes != null && selectedRecipes.Count != 0)
        {
            foreach (KeyValuePair <int, Recipe> r in selectedRecipes)
            {
                Recipe recipe = new Recipe();
                recipe.RecipeId = r.Key;
                recipe          = r.Value;
                menu.Recipes.Add(recipe);
            }
        }

        menu.MenuId     = 0;
        menu.MenuTypeId = 1;

        this.CurrentMenu = menu;

        this.RebindMenuRecipes();

        this.rbnCategoryOneMeal.Checked = true;
        this.rbnCategoryWeekly.Checked  = false;
        this.TablesTitleImg.ImageUrl    = "Images/SubHeader_MeatDetails.png";
        this.divNumDiners.Visible       = true;

        this.RebindMealsDetails();

        this.BindMenuCategories();
    }
Exemplo n.º 5
0
    protected void RebindRecentMenus(int menuId1, int menuId2)
    {
        Menu menu1 = BusinessFacade.Instance.GetMenu(menuId1);
        Menu menu2 = BusinessFacade.Instance.GetMenu(menuId2);

        this.rptRecentMenus.DataSource = new Menu[2] {
            menu1, menu2
        };
        this.rptRecentMenus.DataBind();
    }
Exemplo n.º 6
0
    protected void rptDays_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Menu menu = this.CurrentMenu;

        if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal || menu.MenuTypeId == (int)MenuTypeEnum.QuickMenu)
        {
            System.Web.UI.WebControls.Image tableTopImag = e.Item.FindControl("imgTableTop") as System.Web.UI.WebControls.Image;
            tableTopImag.ImageUrl = "~/Images/bgr_TableMenu.jpg";

            Repeater rptCourses = e.Item.FindControl("rptCourses") as Repeater;

            var list = from item in BusinessFacade.Instance.GetCourseTypes()
                       select new CourseOrMealType(item.CourseTypeId, item.CourseTypeName);
            CourseOrMealType[] courseTypesArray = list.ToArray();

            if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal)
            {
                //CourseOrMealType tempCourseType = courseTypesArray[0];
                //for (int i = 0; i < (courseTypesArray.Length - 1); i++)
                //{
                //    courseTypesArray[i] = courseTypesArray[i + 1];
                //}
                //courseTypesArray[courseTypesArray.Length - 1] = tempCourseType;
                rptCourses.DataSource = courseTypesArray;
            }
            else
            {
                rptCourses.DataSource = courseTypesArray.Where(cmt => cmt.CourseOrMealTypeId == 0);
            }

            rptCourses.DataBind();
        }
        if (menu.MenuTypeId == (int)MenuTypeEnum.Weekly)
        {
            MealDayOfWeek mdow = e.Item.DataItem as MealDayOfWeek;
            if (mdow != null)
            {
                System.Web.UI.WebControls.Image tableTopImag = e.Item.FindControl("imgTableTop") as System.Web.UI.WebControls.Image;
                tableTopImag.ImageUrl = "~/Images/bgr_Table" + mdow.DayId + ".jpg";
            }
            Repeater rptCourses = e.Item.FindControl("rptCourses") as Repeater;

            var list = from item in BusinessFacade.Instance.GetMealTypes()
                       select new CourseOrMealType(item.MealTypeId, item.MealTypeName);

            CourseOrMealType[] mealTypesArray = list.ToArray();
            rptCourses.DataSource = mealTypesArray;
            rptCourses.DataBind();
        }
    }
Exemplo n.º 7
0
    protected void RebindMealsDetails()
    {
        Menu menu = CurrentMenu;

        if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal || menu.MenuTypeId == (int)MenuTypeEnum.QuickMenu)
        {
            MealDayOfWeek[] fakeDaysOfWeek = new MealDayOfWeek[1] {
                new MealDayOfWeek(1, MyGlobalResources.Sunday)
            };
            rptDays.DataSource = fakeDaysOfWeek;
            rptDays.DataBind();
        }

        if (menu.MenuTypeId == (int)MenuTypeEnum.Weekly)
        {
            rptDays.DataSource = MealDayOfWeek;
            rptDays.DataBind();
        }
    }
Exemplo n.º 8
0
    protected void RebindMenuDetails()
    {
        Menu menu = CurrentMenu;

        if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal || menu.MenuTypeId == (int)MenuTypeEnum.QuickMenu)
        {
            rbnCategoryOneMeal.Checked    = true;
            rbnCategoryWeekly.Checked     = false;
            TablesTitleImg.ImageUrl       = "Images/SubHeader_MeatDetails.png";
            divNumDiners.Visible          = true;
            ddlChooseCourse.Visible       = true;
            ddlChooseCourse.SelectedValue = "-1";
            ddlChooseDay.Visible          = false;
            ddlChooseMeal.Visible         = false;

            if (menu.Meals.Count > 0)
            {
                txtNumDiners.Text = menu.Meals.ToArray()[0].Diners.ToString(); //all meals (courses) should have the same diners number.
            }
        }
        else
        {
            rbnCategoryOneMeal.Checked  = false;
            rbnCategoryWeekly.Checked   = true;
            TablesTitleImg.ImageUrl     = "Images/SubHeader_WeklyMenu.png"; //Change to designer's image.
            divNumDiners.Visible        = false;
            ddlChooseCourse.Visible     = false;
            ddlChooseDay.Visible        = true;
            ddlChooseDay.SelectedValue  = "0";
            ddlChooseMeal.Visible       = true;
            ddlChooseMeal.SelectedValue = "0";
        }

        chxPulicMenu.Checked    = menu.IsPublic;
        txtMenuName.Text        = menu.MenuName;
        txtMenuDescription.Text = menu.Description;
        txtMenuTags.Text        = menu.Tags;
        txtEmbeddedVideo.Text   = menu.EmbeddedVideo;
        txtCategories.Text      = this.GetCategoriesString(menu.MCategories.ToArray());

        RebindMealsDetails();
    }
Exemplo n.º 9
0
    protected void txtServings_TextChanged(object sender, EventArgs e)
    {
        Menu menu = this.CurrentMenu;

        TextBox txtServings = sender as TextBox;

        if (txtServings != null)
        {
            int   recipeId        = 0;
            int[] mealIdentifiers = GetMealIdentifiers(txtServings.Attributes["mealSignature"]);
            if (int.TryParse(txtServings.Attributes["recipeId"], out recipeId) && mealIdentifiers != null && mealIdentifiers.Length == 3)
            {
                Meal mealToChange = null;
                // TODO: change all the occurances of this code to "switch", and try to do it with a delegate, that point to different methods
                // according to the menuTypeId. These methods will get a menu object (menuToSave) and a meal object (from menu) or the whole menu object (menu)

                switch (menu.MenuTypeId)
                {
                case (int)MenuTypeEnum.QuickMenu:
                    mealToChange = menu.Meals.SingleOrDefault(me => me.MealTypeId == mealIdentifiers[1]);
                    break;

                case (int)MenuTypeEnum.OneMeal:
                    mealToChange = menu.Meals.SingleOrDefault(me => me.CourseTypeId == mealIdentifiers[2]);
                    break;

                case (int)MenuTypeEnum.Weekly:
                    mealToChange = menu.Meals.SingleOrDefault(me => me.DayIndex == mealIdentifiers[0] && me.MealTypeId == mealIdentifiers[1]);
                    break;
                }

                if (mealToChange != null)
                {
                    MealRecipe recipeToChange = mealToChange.MealRecipes.SingleOrDefault(re => re.RecipeId == recipeId);
                    if (recipeToChange != null)
                    {
                        recipeToChange.Servings = int.Parse(txtServings.Text);
                    }
                }
            }
        }
    }
Exemplo n.º 10
0
    protected void lnkRemove_Click(object sender, EventArgs e)
    {
        Menu menu = this.CurrentMenu;

        LinkButton lnkBtn = sender as LinkButton;

        int recipeId;

        if (lnkBtn != null && int.TryParse(lnkBtn.Attributes["recipeId"], out recipeId))
        {
            foreach (Meal meal in menu.Meals)
            {
                MealRecipe mealRecipeToRemove = meal.MealRecipes.SingleOrDefault(mr => mr.RecipeId == recipeId);
                if (mealRecipeToRemove != null)
                {
                    meal.MealRecipes.Remove(mealRecipeToRemove);
                }
            }

            Recipe menuRecipeToRemove = menu.Recipes.SingleOrDefault(mr => mr.RecipeId == recipeId);

            if (menuRecipeToRemove != null)
            {
                menu.Recipes.Remove(menuRecipeToRemove);
            }

            Dictionary <int, Recipe> selectedRecipes = Utils.SelectedRecipes;
            selectedRecipes.Remove(recipeId);
        }

        CurrentMenu = menu;

        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "setDirty", "setDirty();", true);

        RebindMenuRecipes();
        RebindMealsDetails();
        upSelectedRecipes.Update();
        upMealsDetails.Update();
    }
Exemplo n.º 11
0
    protected void btnCatOK_Click(object sender, EventArgs e)
    {
        Menu menu = this.CurrentMenu;

        menu.MCategories.Clear();
        string updatedCategoriesStr = "";

        foreach (TreeNode node in this.tvCategories.CheckedNodes)
        {
            MCategory mcat = new MCategory();
            mcat.MCategoryId = menu.MenuId;
            mcat.MCategoryId = int.Parse(node.Value);
            menu.MCategories.Add(mcat);
            updatedCategoriesStr += node.Text + ", ";
        }
        updatedCategoriesStr = updatedCategoriesStr.Remove(updatedCategoriesStr.Length - 2);

        this.BindMenuCategories();

        this.txtCategories.Text = updatedCategoriesStr;
        this.upCategories.Update();
    }
Exemplo n.º 12
0
    protected void ChangeServings(object sender, CommandEventArgs e)
    {
        int  recipeId = Convert.ToInt32(e.CommandArgument);
        Menu menu     = CurrentMenu;

        //Recipe recipe1 = BusinessFacade.Instance.GetRecipe(recipeId);

        //Recipe menuRecipe = menu.Recipes.SingleOrDefault(x => x.RecipeId == recipeId);
        //if (menuRecipe != null)
        //{
        //    MealRecipe mealRecipe = (from p in menu.Meals
        //                             from p1 in p.MealRecipes
        //                             where p.MealId == p1.MealId && p.MenuId == menu.MenuId && p1.RecipeId == recipeId && p1.Meal != null
        //                             select new MealRecipe
        //                                 {
        //                                     RecipeId = recipeId,
        //                                     Servings = p1.Servings,
        //                                     Recipe = menuRecipe.Recipe,
        //                                     MealId = p.MealId
        //                                 }).SingleOrDefault();

        //    if (mealRecipe != null)
        //    {
        //        switch (e.CommandName)
        //        {
        //            case "Increase":
        //                mealRecipe.Servings += menuRecipe.Recipe.Servings;
        //                break;
        //            case "Decrease":
        //                if (mealRecipe.Servings > menuRecipe.Recipe.Servings)
        //                    mealRecipe.Servings -= menuRecipe.Recipe.Servings;
        //                break;
        //        }

        //        MealRecipe recipe = menuRecipe.Recipe.MealRecipes.SingleOrDefault(x => x.MealId == mealRecipe.MealId && x.Meal != null);
        //        if (recipe != null) recipe.Servings = mealRecipe.Servings;
        //    }
        //}
    }
Exemplo n.º 13
0
    protected void RebindMenuRecipes()
    {
        Menu menu = CurrentMenu;

        Dictionary <int, Recipe> recipes = new Dictionary <int, Recipe>();

        foreach (Recipe r in menu.Recipes)
        {
            recipes.Add(r.RecipeId, r);
        }

        if (recipes.Count > 0)
        {
            dlRecipes.DataSource = recipes;
            dlRecipes.DataBind();
        }
        else
        {
            dlRecipes.Visible = false;
            lblStatus.Visible = true;
            lblStatus.Text    = "לא נבחרו מתכונים";
        }
    }
Exemplo n.º 14
0
    protected void removeFromMeal_Click(object sender, EventArgs e)
    {
        Menu menu = this.CurrentMenu;

        LinkButton lnkBtn = sender as LinkButton;

        if (lnkBtn != null)
        {
            string mealSignature = lnkBtn.Attributes["mealSignature"];
            int    recipeId;

            if (!string.IsNullOrEmpty(mealSignature) && int.TryParse(lnkBtn.Attributes["recipeId"], out recipeId))
            {
                int[] mealIdentifiers = GetMealIdentifiers(mealSignature);

                Meal currentMeal = null;              //no mealId at this stage. meal is identified by day / meal type / course type.

                switch (menu.MenuTypeId)
                {
                case (int)MenuTypeEnum.QuickMenu:
                    currentMeal = menu.Meals.SingleOrDefault(me => me.MealTypeId == mealIdentifiers[1]);
                    break;

                case (int)MenuTypeEnum.OneMeal:
                    currentMeal = menu.Meals.SingleOrDefault(me => me.CourseTypeId == mealIdentifiers[2]);
                    break;

                case (int)MenuTypeEnum.Weekly:
                    currentMeal = menu.Meals.SingleOrDefault(me => me.DayIndex == mealIdentifiers[0] && me.MealTypeId == mealIdentifiers[1]);
                    break;
                }

                //if (menu.MenuTypeId == (int)MenuTypeEnum.QuickMenu) //only one meal in the menu
                //{
                //    currentMeal = menu.Meals.SingleOrDefault(me => me.MealTypeId == mealIdentifiers[1]);
                //}
                //if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal)
                //{
                //    currentMeal = menu.Meals.SingleOrDefault(me => me.CourseTypeId == mealIdentifiers[2]);
                //}
                //else
                //{
                //    currentMeal = menu.Meals.SingleOrDefault(me => me.DayIndex == mealIdentifiers[0] && me.MealTypeId == mealIdentifiers[1]);
                //}

                if (currentMeal != null)
                {
                    MealRecipe recipe = currentMeal.MealRecipes.SingleOrDefault(mr => mr.RecipeId == recipeId);
                    if (recipe != null)
                    {
                        currentMeal.MealRecipes.Remove(recipe);
                        //if (currentMeal.MealRecipes.Count == 0)
                        //{
                        //    menu.Meals.Remove(currentMeal);
                        //}
                    }
                }

                this.CurrentMenu = menu;

                RebindMealsDetails();
                this.upMealsDetails.Update();
                this.RebindMenuRecipes();
                this.upSelectedRecipes.Update();
            }
        }
    }
Exemplo n.º 15
0
    public static void AddToMenu_DnD(int recipeId, string mealSignature)
    {
        Menu menu = HttpContext.Current.Session["currentMenu"] as Menu;

        Meal meal = null;

        int[] mealIdentifiers = GetMealIdentifiers(mealSignature);

        int dayIndex     = mealIdentifiers[0];
        int mealTypeId   = mealIdentifiers[1];
        int courseTypeId = mealIdentifiers[2];


        if (mealIdentifiers != null && mealIdentifiers.Length == 3)
        {
            if (menu.MenuTypeId == (int)MenuTypeEnum.QuickMenu) //only one meal in the menu
            {
                meal = menu.Meals.SingleOrDefault(me => me.MealTypeId == mealTypeId);
            }
            else if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal)
            {
                meal = menu.Meals.SingleOrDefault(me => me.CourseTypeId == courseTypeId);
            }
            else
            {
                meal = menu.Meals.SingleOrDefault(me => me.DayIndex == dayIndex && me.MealTypeId == mealTypeId);
            }

            if (meal == null)
            {
                meal              = new Meal();
                meal.MealId       = 0;
                meal.CourseTypeId = courseTypeId;
                meal.DayIndex     = dayIndex;
                meal.MealTypeId   = mealTypeId;
                meal.CreatedDate  = DateTime.Now;
                meal.ModifiedDate = DateTime.Now;

                menu.Meals.Add(meal);
            }

            //Page page = HttpContext.Current.Handler as Page;
        }

        MealRecipe mealRecipe = new MealRecipe();

        Recipe menuRec = menu.Recipes.SingleOrDefault(mr => mr.RecipeId == recipeId);

        if (menuRec != null)
        {
            mealRecipe.Recipe   = menuRec;
            mealRecipe.Servings = menuRec.Servings;
        }

        MealRecipe sameMealRecipe = meal.MealRecipes.SingleOrDefault(smr => smr.RecipeId == mealRecipe.RecipeId);

        if (sameMealRecipe == null)
        {
            meal.MealRecipes.Add(mealRecipe);
        }

        HttpContext.Current.Session["currentMenu"] = menu;
    }
Exemplo n.º 16
0
    //note: the "detour" on the way to this method (through a JS function that clicks a hidden button) is neccessary because if this method
    //is called directly from within the "poping" panel, it forces "full" postback for some reason. In this way it is avoided, and selection
    //flow seems "smoother".
    protected void btnTmpOK_Click(object sender, EventArgs e)
    {
        Menu menu = CurrentMenu;

        //get relevant meal, or create it if it doesn't exist.
        Meal meal;
        int? dayIndex = null, courseTypeId = null;
        int  mealTypeId;

        switch ((MenuTypeEnum)menu.MenuTypeId)
        {
        case MenuTypeEnum.QuickMenu:
            mealTypeId   = 4;
            courseTypeId = 0;

            meal = menu.Meals.SingleOrDefault(me => me.MealTypeId == mealTypeId);
            break;

        case MenuTypeEnum.OneMeal:
            courseTypeId = int.Parse(ddlChooseCourse.SelectedItem.Value);
            if (courseTypeId == -1)
            {
                return;
            }

            mealTypeId = 4;

            meal = menu.Meals.SingleOrDefault(me => me.CourseTypeId == courseTypeId);
            break;

        default:
            dayIndex   = int.Parse(ddlChooseDay.SelectedItem.Value);
            mealTypeId = int.Parse(ddlChooseMeal.SelectedItem.Value);
            if (dayIndex == 0 || mealTypeId == 0)
            {
                return;
            }

            meal = menu.Meals.SingleOrDefault(me => me.DayIndex == dayIndex && me.MealTypeId == mealTypeId);
            break;
        }

        if (meal == null)
        {
            meal = new Meal
            {
                MealId       = 0,
                CourseTypeId = courseTypeId,
                DayIndex     = dayIndex,
                MealTypeId   = mealTypeId,
                CreatedDate  = DateTime.Now,
                ModifiedDate = DateTime.Now
            };

            menu.Meals.Add(meal);
        }

        //get recipe id, create MealRecipe, and add to MealRecipes of the current / new meal.
        int recipeId;
        int servingsNum;

        bool succeeded = int.TryParse(hfRecipeId.Value, out recipeId);

        if (succeeded)
        {
            MealRecipe mealRecipe = new MealRecipe();

            Recipe menuRecipe = menu.Recipes.SingleOrDefault(mr => mr.RecipeId == recipeId);
            if (menuRecipe != null)
            {
                mealRecipe.Recipe = menuRecipe;

                int  expectedServings;
                bool tryParse = int.TryParse(hfExpectedServings.Value, out expectedServings);
                if (tryParse)
                {
                    mealRecipe.Servings = expectedServings;
                }
            }

            MealRecipe sameMealRecipe = meal.MealRecipes.SingleOrDefault(smr => smr.RecipeId == mealRecipe.RecipeId);
            if (sameMealRecipe == null)
            {
                meal.MealRecipes.Add(mealRecipe);
            }
        }


        //save menu changes and display changed menu
        CurrentMenu = menu;

        RebindMealsDetails();
        upMealsDetails.Update();
        RebindMenuRecipes();
        upSelectedRecipes.Update();
    }
Exemplo n.º 17
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            Menu menu = CurrentMenu;

            int    menuTypeId    = 0;
            bool   isPublic      = false;
            string menuName      = this.txtMenuName.Text;
            string description   = this.txtMenuDescription.Text;
            string tags          = this.txtMenuTags.Text;
            string embeddedVideo = this.txtEmbeddedVideo.Text;
            int?   diners        = null;

            if (rbnCategoryOneMeal.Checked)
            {
                menuTypeId = (int)MenuTypeEnum.OneMeal;

                if (!string.IsNullOrEmpty(txtNumDiners.Text))
                {
                    diners = int.Parse(txtNumDiners.Text);
                }
            }
            else if (rbnCategoryWeekly.Checked)
            {
                menuTypeId = (int)MenuTypeEnum.Weekly;
            }
            if (chxPulicMenu.Checked)
            {
                isPublic = true;
            }

            if (string.IsNullOrEmpty(menuName))
            {
                menuName = string.Empty;
            }
            if (string.IsNullOrEmpty(description))
            {
                description = string.Empty;
            }
            if (string.IsNullOrEmpty(tags))
            {
                tags = string.Empty;
            }
            if (string.IsNullOrEmpty(embeddedVideo))
            {
                embeddedVideo = null;
            }

            if (fuMenuPicture.HasFile && fuMenuPicture.PostedFile != null && ImageHelper.IsImage(fuMenuPicture.PostedFile.FileName))
            {
                Bitmap bitmap = ImageHelper.ResizeImage(new Bitmap(this.fuMenuPicture.PostedFile.InputStream, false), 300, 231);  //see if needs change!
                menu.Picture = ImageHelper.GetBitmapBytes(bitmap);
            }

            int userId = ((BasePage)Page).UserId;
            //can unregistered users add a new recipe? should I deny access to this page to unregistered guests?

            menu.MenuName      = menuName;
            menu.Description   = description;
            menu.Tags          = tags;
            menu.EmbeddedVideo = embeddedVideo;

            if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal || menu.MenuTypeId == (int)MenuTypeEnum.QuickMenu)
            {
                foreach (Meal meal in menu.Meals.ToArray())
                {
                    meal.Diners = diners;
                }
            }
            if (menu.MenuId == 0)
            {
                menu.MenuTypeId = menuTypeId;
                menu.UserId     = userId;
            }

            menu.IsPublic = isPublic;

            for (int i = 0; i < menu.Meals.ToArray().Length; i++)
            {
                if (menu.Meals.ToArray()[i].MealRecipes.Count == 0)
                {
                    menu.Meals.Remove(menu.Meals.ToArray()[i]);
                }
            }

            Meal[]       meals    = menu.Meals.ToArray();
            RepeaterItem daysItem = null;

            for (int mealInd = 0; mealInd < meals.Length; mealInd++)
            {
                if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal || menu.MenuTypeId == (int)MenuTypeEnum.QuickMenu)
                {
                    daysItem = rptDays.Items[0];
                    Repeater courses = (Repeater)daysItem.FindControl("rptCourses");
                    if (courses != null)
                    {
                        foreach (RepeaterItem coursesItem in courses.Items)
                        {
                            if (coursesItem.ItemIndex == 6)
                            {
                                meals[mealInd].Comments = "";
                                TextBox comment = (TextBox)coursesItem.FindControl("TextBoxComments");
                                if (!string.IsNullOrEmpty(comment.Text))
                                {
                                    meals[mealInd].Comments = comment.Text;
                                }
                            }
                        }
                    }
                }

                if (menu.MenuTypeId == (int)MenuTypeEnum.Weekly)
                {
                    int dayIndex = meals[mealInd].DayIndex.Value;
                    daysItem = rptDays.Items[dayIndex - 1];

                    Repeater courses = (Repeater)daysItem.FindControl("rptCourses");
                    if (courses != null)
                    {
                        foreach (RepeaterItem coursesItem in courses.Items)
                        {
                            if (coursesItem.ItemIndex == 4)
                            {
                                //TextBox comment = (TextBox) coursesItem.FindControl("TextBoxComments");
                                //if (!string.IsNullOrEmpty(comment.Text))
                                //{
                                //    meals[mealInd].Comments = comment.Text;
                                //}

                                meals[mealInd].Comments = _comments[dayIndex - 1];
                            }
                        }
                    }
                }
            }

            int returnedMenuId;
            BusinessFacade.Instance.CreateOrUpdateMenu(menu, out returnedMenuId);

            if (returnedMenuId != 0)
            {
                Utils.SelectedRecipes = null;
                CurrentMenu           = null;
                string url = string.Format("~/MenuDetails.aspx?menuId={0}", returnedMenuId);
                Response.Redirect(url);
            }
        }
        catch (Exception exception)
        {
        }
    }
Exemplo n.º 18
0
    protected void rptCourses_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        Menu menu = this.CurrentMenu;

        Meal          currentMeal          = null;
        MealDayOfWeek currentWeekDay       = null;
        int           currentWeekDayId     = 0;
        string        currentMealSignature = "";

        int currentCourseOrMenuTypeId = ((CourseOrMealType)e.Item.DataItem).CourseOrMealTypeId;

        RepeaterItem parentItem = e.Item.Parent.Parent as RepeaterItem;

        if (parentItem != null)
        {
            currentWeekDay = parentItem.DataItem as MealDayOfWeek;
        }
        if (currentWeekDay != null)
        {
            currentWeekDayId = currentWeekDay.DayId;
        }

        TextBox txtComments = null;

        if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal && currentCourseOrMenuTypeId == 6)
        {
            txtComments                     = e.Item.FindControl("TextBoxComments") as TextBox;
            txtComments.Visible             = true;
            txtComments.Attributes["DayId"] = currentWeekDayId.ToString();
            if (_comments != null && _comments.Count != 0)
            {
                txtComments.Text = _comments[currentWeekDayId - 1];
            }
        }

        if (menu.MenuTypeId == (int)MenuTypeEnum.Weekly && currentCourseOrMenuTypeId == 5)
        {
            txtComments                     = e.Item.FindControl("TextBoxComments") as TextBox;
            txtComments.Visible             = true;
            txtComments.Attributes["DayId"] = currentWeekDayId.ToString();
            if (_comments != null && _comments.Count != 0)
            {
                txtComments.Text = _comments[currentWeekDayId - 1];
            }
        }

        if (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal)
        {
            foreach (Meal m in this.CurrentMenu.Meals.ToArray())
            {
                if (m.CourseTypeId == currentCourseOrMenuTypeId)
                {
                    currentMeal = m;
                }

                if (currentCourseOrMenuTypeId == 6 && !string.IsNullOrEmpty(m.Comments))
                {
                    if (string.IsNullOrEmpty(txtComments.Text))
                    {
                        txtComments.Text = m.Comments;
                        _comments[currentWeekDayId - 1] = m.Comments;
                    }
                }
            }

            currentMealSignature = "d0m4c" + currentCourseOrMenuTypeId;
        }
        if (menu.MenuTypeId == (int)MenuTypeEnum.Weekly)
        {
            foreach (Meal m in this.CurrentMenu.Meals.ToArray())
            {
                if (m.MealTypeId == currentCourseOrMenuTypeId && m.DayIndex == currentWeekDayId)
                {
                    currentMeal = m;
                }

                if (currentCourseOrMenuTypeId == 5 && m.DayIndex == currentWeekDayId && !string.IsNullOrEmpty(m.Comments))
                {
                    if (string.IsNullOrEmpty(txtComments.Text))
                    {
                        txtComments.Text = m.Comments;
                        _comments[currentWeekDayId - 1] = m.Comments;
                    }
                }
            }

            currentMealSignature = "d" + currentWeekDayId + "m" + currentCourseOrMenuTypeId + "c0";
        }

        // for identification of relevant meal after recipe was dropped on the table cell.
        HtmlTableCell tdMealRecipes = e.Item.FindControl("tdMealRecipes") as HtmlTableCell;

        if (tdMealRecipes != null)
        {
            tdMealRecipes.Attributes["meal_signature"] = currentMealSignature;
        }

        if (currentMeal == null)
        {
            tdMealRecipes.Controls.Add(new LiteralControl("&nbsp;")); //for IE
            return;
        }
        if (currentMeal.MealRecipes.Count == 0)
        {
            tdMealRecipes.Controls.Add(new LiteralControl("&nbsp;")); //for IE
        }

        if (this.CurrentMenu.MenuTypeId == (int)MenuTypeEnum.OneMeal && txtComments != null)
        {
            txtComments.Text = currentMeal.Comments;
        }

        if (this.CurrentMenu.MenuTypeId == (int)MenuTypeEnum.Weekly)
        {
            HtmlTableCell tdDinersNum = e.Item.FindControl("tdDinersNum") as HtmlTableCell;
            if (tdDinersNum != null)
            {
                tdDinersNum.Style["width"]          = "33px";
                tdDinersNum.Style["padding-right"]  = "2px";
                tdDinersNum.Style["padding-top"]    = "5px";
                tdDinersNum.Style["padding-bottom"] = "5px";
            }

            TextBox txtDinersNum = e.Item.FindControl("txtDinersNum") as TextBox;
            if (txtDinersNum != null)
            {
                txtDinersNum.Attributes["mealSignature"] = this.GetMealSignature(currentMeal);
                txtDinersNum.Text    = currentMeal.Diners.ToString();
                txtDinersNum.Visible = true;
            }
        }

        Repeater rpt = e.Item.FindControl("rptRecipes") as Repeater;

        if (rpt != null)
        {
            rpt.DataSource = currentMeal.MealRecipes.ToArray();
            rpt.DataBind();
        }
    }
Exemplo n.º 19
0
    protected void EditMenu(int menuId)
    {
        try
        {
            titleImg.ImageUrl = "~/Images/Header_EditMenu.png";

            Menu menu = BusinessFacade.Instance.GetMenuEx(menuId);

            if (menu != null)
            {
                if ((((BasePage)Page).UserType != 1) && (menu.UserId != ((BasePage)Page).UserId) && !(menu.IsPublic) || menu.IsDeleted)
                {
                    AppEnv.MoveToDefaultPage();
                }

                Dictionary <int, Recipe> selectedRecipes = Utils.SelectedRecipes;

                foreach (Recipe mr in menu.Recipes)
                {
                    selectedRecipes.Add(mr.RecipeId, mr);
                }

                if (selectedRecipes != null && selectedRecipes.Count != 0)
                {
                    foreach (KeyValuePair <int, Recipe> r in selectedRecipes)
                    {
                        Recipe menuRecipe = new Recipe {
                            RecipeId = r.Key
                        };

                        bool containsRecipe = false;
                        foreach (Recipe mr in menu.Recipes)
                        {
                            if (mr.RecipeId == r.Key)
                            {
                                containsRecipe   = true;
                                r.Value.Servings = mr.Servings;

                                MealRecipe mealRecipe = (from p in menu.Meals
                                                         from p1 in p.MealRecipes
                                                         where p.MealId == p1.MealId && p.MenuId == menu.MenuId && p1.RecipeId == r.Key
                                                         select new MealRecipe
                                {
                                    RecipeId = r.Key,
                                    Servings = p1.Servings,
                                    Recipe = r.Value,
                                    MealId = p.MealId
                                }).SingleOrDefault();

                                if (mealRecipe != null)
                                {
                                    r.Value.Servings = mealRecipe.Servings;
                                    mr.Servings      = mealRecipe.Servings;
                                }
                            }
                        }
                        if (!containsRecipe)
                        {
                            menu.Recipes.Add(menuRecipe);
                        }
                    }
                }


                bool isOneMeal = (menu.MenuTypeId == (int)MenuTypeEnum.OneMeal || menu.MenuTypeId == (int)MenuTypeEnum.QuickMenu);

                rbnCategoryOneMeal.Enabled = isOneMeal;
                rbnCategoryWeekly.Enabled  = !isOneMeal;


                CurrentMenu = menu;

                RebindMenuRecipes();

                RebindMenuDetails();

                BindMenuCategories();
            }
            else
            {
                AppEnv.MoveToDefaultPage();
            }
        }
        catch (Exception)
        {
        }
    }