Exemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (this.Display == RecipeDisplayEnum.ByCategory)
            {
                int count = this.RebindCategories(this.CategoryId);
                this.categories.Visible = true;
                if (count == 0)
                {
                    this.pnlCategories.Visible = false;
                }
            }
            if (this.Display == RecipeDisplayEnum.BySearchSimple)
            {
                //this.simpleSearch.Visible = true;
                //this.btnSearch.Visible = true;
                //this.txtSearchTerm.Text = (!string.IsNullOrEmpty(Request["term"])) ? Request["term"] : "";
                //this.btnSearch.CommandArgument = "BySearchSimple";
            }
            if (this.Display == RecipeDisplayEnum.BySearchAdvanced)
            {
                this.BindMenuCategories();
                //this.simpleSearch.Visible = true;
                this.advancedSearch.Visible = true;
                //this.btnSearch.Visible = true;
                //this.txtSearchTerm.Text = (!string.IsNullOrEmpty(Request["term"])) ? Request["term"] : "";
                this.txtDiners.Text   = (!string.IsNullOrEmpty(Request["serv"])) ? Request["serv"] : "";
                this.txtCategory.Text = "";
                //this.btnSearch.CommandArgument = "BySearchAdvanced";
            }

            EmphasizeCurrentSearch(this.Display);

            MyBuyList.Shared.Entities.User currentUser = BusinessFacade.Instance.GetUser(((BasePage)this.Page).UserId);
            string email = (currentUser != null) ? currentUser.Email : string.Empty;
            this.ucSendMailToFriend.BindItemDetails("Menu", 0, string.Empty, email);

            RebindRecipes();

            // 17.09.2010
            // Load categories at page load
            MCategory[] categories = BusinessFacade.Instance.GetMenusCategoriesList(((BasePage)this.Page).UserId);
            var         list       = from mcat in categories.Where(mcat => mcat.ParentMCategoryId == null).ToArray()
                                     select mcat;

            MCategory[] categoryList = list.ToArray();
            MenusSearchControl1.FillList(categoryList, this.MenuCategoryChangeBaseUrl);

            if (CurrUser != null)
            {
                ucShoppingList1.UserId = CurrUser.UserId;
            }
        }
    }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (CurrUser != null)
            {
                ucShoppingList1.UserId = CurrUser.UserId;
            }

            if (!IsPostBack)
            {
                if (this.Display == RecipeDisplayEnum.ByCategory)
                {
                    int count = this.RebindCategories(this.CategoryId);
                    this.categories.Visible = true;
                    if (count == 0)
                    {
                        this.pnlCategories.Visible = false;
                    }
                }
                //if (this.Display == RecipeDisplayEnum.BySearchSimple)
                //{
                //    this.simpleSearch.Visible = true;
                //    this.btnSearch.Visible = true;
                //    this.txtSearchTerm.Text = (!string.IsNullOrEmpty(Request["term"])) ? Request["term"] : "" ;
                //    this.btnSearch.CommandArgument = "BySearchSimple";
                //}
                if (this.Display == RecipeDisplayEnum.BySearchAdvanced)
                {
                    //this.simpleSearch.Visible = true;
                    //this.advancedSearch.Visible = true;
                    //this.btnSearch.Visible = true;
                    //this.txtSearchTerm.Text = (!string.IsNullOrEmpty(Request["term"])) ? Request["term"] : "" ;
                    //this.txtServings.Text = (!string.IsNullOrEmpty(Request["serv"])) ? Request["serv"] : "";
                    //this.txtCategory.Text = "";
                    //this.btnSearch.CommandArgument = "BySearchAdvanced";
                }

                //EmphasizeCurrentSearch(this.Display);

                MyBuyList.Shared.Entities.User currentUser = BusinessFacade.Instance.GetUser(((BasePage)this.Page).UserId);
                string email = (currentUser != null) ? currentUser.Email : string.Empty;
                //this.ucSendMailToFriend.BindItemDetails("Recipe", 0, string.Empty, email);

                RebindRecipes();

                // 13.10.2010
                // Load categories at page load
                //Category[] categories = BusinessFacade.Instance.GetRecipesCategoriesList(((BasePage)this.Page).UserId);
                //var list = from cat in categories.Where(cat => cat.ParentCategoryId == null).ToArray()
                //           select new SRL_Category(cat.CategoryId, cat.CategoryName, cat.ParentCategoryId, cat.RecipesCount);

                //SRL_Category[] categoryList = list.ToArray();
                //RecipesFilter1.FillList(categoryList, this.RecipeCategoryChangeBaseUrl);
            }
        }
        catch (Exception ex)
        {
            Logger.Write("PageLoad failed", ex, Logger.Level.Error);
        }
    }
Exemplo n.º 3
0
    private void Rebind()
    {
        Recipe recipe = BusinessFacade.Instance.GetRecipe(this.RecipeId);

        if (recipe != null)
        {
            PlaceHolder1.Visible = ((BasePage)Page).UserId == recipe.UserId;
            PlaceHolder2.Visible = ((BasePage)Page).UserId == recipe.UserId;

            this.lblRecipeName.Text = recipe.RecipeName;
            this.lblServNumber.Text = recipe.Servings.ToString();

            if (recipe.Tags != null)
            {
                this.lblRecipeTags.Text = recipe.Tags;
            }
            if (recipe.Description != null)
            {
                this.lblRecipeDescription.Text = recipe.Description;
            }

            if (recipe.DifficultyLevel != null)
            {
                this.txtDifficulty.Text = this.GetDifficultyLevelString(recipe.DifficultyLevel.Value);
            }

            if (recipe.PreperationTime != null)
            {
                string units;
                this.lblPrepTime.Text = this.GetTimeInCorrectUnits(recipe.PreperationTime.Value, out units).ToString() + " " + units;
            }

            if (recipe.CookingTime != null)
            {
                string units;
                this.lblCookTime.Text = this.GetTimeInCorrectUnits(recipe.CookingTime.Value, out units).ToString() + " " + units;
            }

            if (!string.IsNullOrEmpty(recipe.Remarks))
            {
                this.lblRemarks.Text = recipe.Remarks;
            }
            else
            {
                this.recipe_remarks.Visible = false;
            }

            if (!string.IsNullOrEmpty(recipe.PreparationMethod))
            {
                this.txtPreparationMethod.Text = recipe.PreparationMethod.Replace("\n", "<br />");
            }

            if (!string.IsNullOrEmpty(recipe.Tools))
            {
                this.txtTools.Text = recipe.Tools.Replace("\n", "<br />");
            }

            bool isInMyFavorites = (recipe.UserFavoriteRecipes.SingleOrDefault(ufr => ufr.UserId == ((BasePage)this.Page).UserId) != null);
            if (isInMyFavorites)
            {
                this.myFavoritesTopTag.Visible = true;
            }
            else
            {
                this.myFavoritesTopTag.Visible = false;
            }

            lblAllFavorites.Text = recipe.UserFavoriteRecipes.Count.ToString();

            lblAllMenus.Text = recipe.MenuRecipes.Count.ToString();

            string str = "";
            foreach (RecipeCategory rc in recipe.RecipeCategories)
            {
                str += rc.Category.CategoryName + ", ";
            }
            str = str.Remove(str.Length - 2);
            this.lblRecipeCategories.Text = str;

            dlistIngredients.DataSource = recipe.Ingredients;
            dlistIngredients.DataBind();

            bool allowRecipeEdit = (bool)((recipe.UserId == ((BasePage)Page).UserId) || (((BasePage)Page).UserType == 1));
            lblEditRecipeSeparator.Visible        = allowRecipeEdit;
            lblEditRecipeSeparator_bottom.Visible = allowRecipeEdit;
            //btnEditRecipe.Visible = allowRecipeEdit;
            //btnEditRecipe_bottom.Visible = allowRecipeEdit;
            lblCopyRecipeSeperator.Visible        = allowRecipeEdit;
            lblCopyRecipeSeperator_bottom.Visible = allowRecipeEdit;
            btnDeleteRecipe.Visible        = allowRecipeEdit;
            btnDeleteRecipe_bottom.Visible = allowRecipeEdit;

            UserFavoriteRecipe ufrep = recipe.UserFavoriteRecipes.SingleOrDefault(ufr => ufr.RecipeId == recipe.RecipeId &&
                                                                                  ufr.UserId == ((BasePage)Page).UserId);
            bool isValidUser      = (((BasePage)Page).UserId != -1);
            bool existInFavorites = (ufrep != null);
            lblAddToFavoritesSeparator.Visible          = isValidUser;
            lblAddToFavoritesSeparator_bottom.Visible   = isValidUser;
            btnAddRecipeToFavorites.Visible             = ((!existInFavorites) && isValidUser);
            btnAddRecipeToFavorites_bottom.Visible      = ((!existInFavorites) && isValidUser);
            btnRemoveRecipeFromFavorites.Visible        = ((existInFavorites) && isValidUser);
            btnRemoveRecipeFromFavorites_bottom.Visible = ((existInFavorites) && isValidUser);

            if ((isValidUser) && (((BasePage)Page).UserType == 1))
            //if ((isValidUser))
            {
                btnCopyRecipe.Visible        = true;
                btnCopyRecipe_bottom.Visible = true;
                lblSeparator3.Visible        = true;
                lblSeparator3_bottom.Visible = true;
            }

            //this.btnSendMail.Visible = isValidUser;
            //this.lblSeparator1.Visible = isValidUser;

            //if (allowRecipeEdit && recipe.MenuRecipes.Count > 0)
            if (allowRecipeEdit && recipe.MenuRecipes.Count > 0 && ((BasePage)Page).UserType != 1)
            {
                btnDeleteRecipe.Visible                = false;
                btnDeleteRecipe_bottom.Visible         = false;
                lblDeleteRecipeDisabled.Visible        = true;
                lblDeleteRecipeDisabled_bottom.Visible = true;
                lblDeleteRecipeDisabled.ToolTip        = "לא ניתן למחוק את המתכון משום שהוא קיים בתפריט/ים. אם ברצונך למחוק את המתכון - נא ליצור קשר עם מנהלת האתר.";
                lblDeleteRecipeDisabled_bottom.ToolTip = "לא ניתן למחוק את המתכון משום שהוא קיים בתפריט/ים. אם ברצונך למחוק את המתכון - נא ליצור קשר עם מנהלת האתר";
                //btnEditRecipe.Visible = false;
                //btnEditRecipe_bottom.Visible = false;
                lblEditRecipeDisabled.Visible        = true;
                lblEditRecipeDisabled_bottom.Visible = true;
                lblEditRecipeDisabled.ToolTip        = "לא ניתן לערוך את המתכון משום שהוא קיים בתפריט/ים. אם ברצונך לערוך את המתכון - נא ליצור קשר עם מנהלת האתר.";
                lblEditRecipeDisabled_bottom.ToolTip = "לא ניתן לערוך את המתכון משום שהוא קיים בתפריט/ים. אם ברצונך לערוך את המתכון - נא ליצור קשר עם מנהלת האתר";
            }

            Dictionary <int, Recipe> selectedRecipes = Utils.SelectedRecipes;
            bool isSelectedRecipe = (selectedRecipes.Keys.Contains(recipe.RecipeId));

            if (!isSelectedRecipe)
            {
                this.blkAddRemove.Text        = "הוסף לרשימת קניות";
                this.blkAddRemove_bottom.Text = "הוסף לרשימת קניות";
            }
            else
            {
                this.blkAddRemove.Text                  = "הסר מרשימת קניות";
                this.blkAddRemove_bottom.Text           = "הסר מרשימת קניות";
                this.blkAddRemove.Style["color"]        = "Red";
                this.blkAddRemove_bottom.Style["color"] = "Red";
            }

            bool isCompleteCalculation = false;
            RecipeTotalNutValues[] nutritionalValues = BusinessFacade.Instance.GetRecipeTotalNutValues(this.RecipeId, out isCompleteCalculation);
            if (nutritionalValues == null || nutritionalValues.Length == 0 || !isCompleteCalculation)
            {
                this.divNutritionalValues.Visible          = false;
                this.txtNoDataForNutritionalValues.Visible = true;
                this.txtNoDataForNutritionalValues.Text    = MyGlobalResources.NoDataForNutritionalValues.Replace("\n", "<br>");
            }
            else
            {
                if (rptNutritionalValues != null)
                {
                    this.rptNutritionalValues.DataSource = nutritionalValues;
                    this.rptNutritionalValues.DataBind();
                    this.rptNutritionalValues1.DataSource = nutritionalValues;
                    this.rptNutritionalValues1.DataBind();
                }
            }

            if (recipe.Picture != null)
            {
                this.imgRecipePicture.ImageUrl = "~/ShowPicture.ashx?RecipeId=" + recipe.RecipeId;
            }
            else
            {
                this.imgRecipePicture.ImageUrl = "~/Images/Img_Default.jpg";
            }

            if (!string.IsNullOrEmpty(recipe.VideoLink) && recipe.VideoLink.Contains("object") && recipe.VideoLink.Contains("embed"))
            {
                //adjustment method may not work for embedded videos that are not from youtube.
                this.recipe_video.InnerHtml = this.AdjustVideo(recipe.VideoLink);
            }
            else
            {
                this.recipe_video.Visible = false;
            }

            this.lnkPublisher.Text   = recipe.User.DisplayName;
            this.lblPublishDate.Text = recipe.ModifiedDate.ToString("dd/MM/yyyy");

            string userEmail = string.Empty;
            MyBuyList.Shared.Entities.User currentUser = BusinessFacade.Instance.GetUser(((BasePage)this.Page).UserId);
            if (currentUser != null)
            {
                userEmail = currentUser.Email;
            }
            this.ucSendMailToFriend.BindItemDetails("Recipe", recipe.RecipeId, recipe.RecipeName, userEmail);

            UpdatePanel2.Update();
            UpdatePanel1.Update();
        }
    }