protected void saveButton_Click(object sender, EventArgs e)
    {
        int LastInsertedRecipeId, LastInsertedIngredientId;
        RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
        recipe rObj = new recipe();

        rObj.name     = txtTitle.Text;
        rObj.category = txtCategory.Text;


        rObj.submitted_by = txtSubmitted.Text;
        rObj.cooking_time = txtCookingTime.Text;
        rObj.servings     = txtNumServ.Text;
        rObj.Description  = txtDescription.InnerText;
        rObj.MemberId     = MemberId;
        rdbEnty.recipes.AddObject(rObj);
        rdbEnty.SaveChanges();
        LastInsertedRecipeId = rObj.id;


        int num = 0;

        if (Request.Form["hdnIngridient"] != null)
        {
            int.TryParse(Convert.ToString(Request.Form["hdnIngridient"]), out num);
        }

        if (num > 0)
        {
            saveIngridients(LastInsertedRecipeId, num);
        }

        rdbEnty.SaveChanges();
        Response.Redirect("Recipe.aspx");
    }
    private void saveIngridients(int recipeId, int totalIngridients)
    {
        RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
        string name = ""; int Q = 0; string unit = ""; string qty = "";


        for (int i = 1; i <= totalIngridients; i++)
        {
            name = "";
            qty  = "";
            unit = "";
            Q    = 0;


            if (Request.Form["txtIngridients" + i] != null && !string.IsNullOrWhiteSpace(Request.Form["txtIngridients" + i]))
            {
                name = Convert.ToString(Request.Form["txtIngridients" + i]);
            }

            if (Request.Form["txtQuantity" + i] != null && !string.IsNullOrWhiteSpace(Request.Form["txtQuantity" + i]))
            {
                qty = Convert.ToString(Request.Form["txtQuantity" + i]);

                int.TryParse(qty, out Q);
            }

            if (Request.Form["ddlUnit" + i] != null && !string.IsNullOrWhiteSpace(Request.Form["ddlUnit" + i]))
            {
                unit = Convert.ToString(Request.Form["ddlUnit" + i]);
            }

            if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(unit) && Q > 0)
            {
                ingredient iObj = new ingredient();
                iObj.name     = name;
                iObj.MemberId = MemberId;
                rdbEnty.ingredients.AddObject(iObj);
                rdbEnty.SaveChanges();
                int LastInsertedIngredientId = iObj.id;

                recipe_ingredients riObj = new recipe_ingredients();
                riObj.ingredient_id = LastInsertedIngredientId;
                riObj.recipe_id     = recipeId;
                riObj.name          = name;
                riObj.unit          = unit;
                riObj.quantity      = Q;
                riObj.MemberId      = MemberId;
                rdbEnty.recipe_ingredients.AddObject(riObj);
                rdbEnty.SaveChanges();
            }
        }
    }
        private void DeleteRecipeExecute()
        {
            try
            {
                MessageBoxResult result = MessageBox.Show("Are you sure?", "Confirm Deleting", MessageBoxButton.YesNo);
                switch (result)
                {
                case MessageBoxResult.Yes:
                    using (RecipeDatabaseEntities db = new RecipeDatabaseEntities())
                    {
                        tblRecipe deleteRecipe = new tblRecipe();
                        deleteRecipe = db.tblRecipes.Where(r => r.RecipeID == Recipe.RecipeID).FirstOrDefault();

                        db.tblRecipes.Remove(deleteRecipe);
                        db.SaveChanges();
                    }
                    MessageBox.Show("Recipe Deleted Successfully!");
                    AllRecipes = GetAllRecipes();
                    break;

                case MessageBoxResult.No:
                    break;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
    private void addMoreIngridients(int recipeId)
    {
        RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
        int    ind = int.Parse(Session["ind"].ToString());
        string name = ""; int Q = 0; string unit = "";

        for (int i = 1; i < ind; i++)
        {
            if (Panel1.Controls[i] is TextBox && Panel1.Controls[i].ID.EndsWith("Q"))
            {
                Q = int.Parse(((TextBox)(Panel1.Controls[ind])).Text);
            }
            else if (Panel1.Controls[i] is TextBox)
            {
                name = ((TextBox)(Panel1.Controls[i])).Text;
            }
            else if (Panel1.Controls[i] is DropDownList)
            {
                unit = ((DropDownList)Panel1.Controls[i]).Text;
                ingredient iObj = new ingredient();
                iObj.name     = name;
                iObj.MemberId = MemberId;
                rdbEnty.ingredients.AddObject(iObj);
                rdbEnty.SaveChanges();
                int LastInsertedIngredientId = iObj.id;

                recipe_ingredients riObj = new recipe_ingredients();
                riObj.ingredient_id = LastInsertedIngredientId;
                riObj.recipe_id     = recipeId;
                riObj.unit          = unit;
                riObj.quantity      = Q;
                riObj.MemberId      = MemberId;
                rdbEnty.recipe_ingredients.AddObject(riObj);
                rdbEnty.SaveChanges();
            }
        }
    }
        private void SaveExecute()
        {
            try
            {
                Ingredients                 = GetAllIngredients();
                Recipe.RecipeType           = Type;
                Recipe.RecipeDateOfCreation = DateTime.Now;
                Recipe.RecipeText           = AllIngredientsToString(Ingredients);
                if (Recipe.RecipeText == "")
                {
                    MessageBox.Show("Please choose ingredients.");
                    return;
                }
                using (RecipeDatabaseEntities db = new RecipeDatabaseEntities())
                {
                    Recipe.UserID = User.UserID;
                    db.tblRecipes.Add(Recipe);
                    db.SaveChanges();

                    foreach (tblIngredient ingredient in Ingredients)
                    {
                        tblRecipeIngredient recipeIngredient = new tblRecipeIngredient();
                        recipeIngredient.RecipeID     = Recipe.RecipeID;
                        recipeIngredient.IngredientID = ingredient.IngredientID;
                        db.tblRecipeIngredients.Add(recipeIngredient);
                    }

                    db.SaveChanges();
                }
                MessageBox.Show("Recipe Created Successfully!");
                addRecipe.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
        private void SaveExecute()
        {
            try
            {
                Ingredients = GetAllIngredients();
                using (RecipeDatabaseEntities db = new RecipeDatabaseEntities())
                {
                    tblRecipe oldRecipe = new tblRecipe();
                    oldRecipe = db.tblRecipes.Where(r => r.RecipeID == Recipe.RecipeID).FirstOrDefault();

                    oldRecipe.RecipeName           = Recipe.RecipeName;
                    oldRecipe.Portions             = Recipe.Portions;
                    oldRecipe.RecipeType           = Type;
                    oldRecipe.RecipeDateOfCreation = DateTime.Now;
                    oldRecipe.RecipeText           = AllIngredientsToString(Ingredients);

                    if (oldRecipe.RecipeText == "")
                    {
                        MessageBox.Show("Please choose ingredients.");
                        return;
                    }
                    else
                    {
                        if (User.UserName == "Admin")
                        {
                            oldRecipe.UserID = User.UserID;
                        }
                        if (Ingredients != null)
                        {
                            foreach (tblIngredient ingredient in Ingredients)
                            {
                                tblRecipeIngredient recipeIngredient = new tblRecipeIngredient();
                                recipeIngredient.RecipeID     = Recipe.RecipeID;
                                recipeIngredient.IngredientID = ingredient.IngredientID;
                                db.tblRecipeIngredients.Add(recipeIngredient);
                            }
                        }

                        db.SaveChanges();
                    }
                }
                MessageBox.Show("Recipe Updated Successfully!");
                updateView.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 7
0
    protected void DelRecipe(object sender, EventArgs e)
    {
        int ReqRecipe = Convert.ToInt32(Request.QueryString["recipe"]);
        RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
        recipe robj = new recipe()
        {
            id = ReqRecipe
        };

        rdbEnty.recipes.Attach(robj);
        rdbEnty.recipes.DeleteObject(robj);
        rdbEnty.SaveChanges();

        Response.Redirect("Recipe.aspx");
    }
Esempio n. 8
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        int ReqRecipe = Convert.ToInt32(Request.QueryString["recipe"]);

        if (ReqRecipe > 0)
        {
            RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
            var query = (from p in rdbEnty.recipes
                         where p.id == ReqRecipe
                         select p);
            IEnumerable <recipe> recipeEditList = query.ToList();
            foreach (var recipe1 in recipeEditList)
            {
                ///recipeName.InnerText = recipe1.name;

                //update recipe data
                recipe1.name = txtTitle.Text;

                recipe1.category = txtCategory.Text;

                recipe1.cooking_time = txtCookingTime.Text;
                recipe1.servings     = txtNumServ.Text;
                recipe1.Description  = txtDescription.InnerText;

                rdbEnty.SaveChanges();
            }


            int num = 0;
            if (Request.Form["hdnIngridient"] != null)
            {
                int.TryParse(Convert.ToString(Request.Form["hdnIngridient"]), out num);
            }

            if (num > 0)
            {
                updateIngridients(ReqRecipe, num);
            }

            //Redirect to recipe edit details page.
            Response.Redirect("RecipeDetails.aspx?recipe=" + ReqRecipe);
        }
    }
Esempio n. 9
0
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        if (ValidateFormData())
        {
            Member objMember = new Member();
            objMember.UserName  = txtUser.Text.Trim();
            objMember.Password  = Common.Sha1Hash(txtPassword.Text.Trim());
            objMember.IsActive  = true;
            objMember.CreatedOn = Common.GetCurrentDateTime();

            rdbEnty.Members.AddObject(objMember);
            rdbEnty.SaveChanges();

            gblStrMessage = "<br><span style=\"color:green;font-size:18px;\">Your registration is completed successfully.<br> Please <a href=\"SignIn.aspx\">click here</a> to login.</span>";

            litStatus.Text = gblStrMessage;
        }
        else
        {
            litStatus.Text = gblStrMessage;
        }
    }
Esempio n. 10
0
    private void updateIngridients(int recipeId, int totalIngridients)
    {
        RecipeDatabaseEntities rdbEnty = new RecipeDatabaseEntities();
        string name = ""; int Q = 0; string unit = ""; string qty = "";

        int recipe_ingredientsid = 0;

        for (int i = 1; i <= totalIngridients; i++)
        {
            name = "";
            qty  = "";
            unit = "";
            Q    = 0;

            //Get recipe_ingredientsid.
            if (Request.Form["hdnRecipeIngridientsId" + i] != null && !string.IsNullOrWhiteSpace(Request.Form["hdnRecipeIngridientsId" + i]))
            {
                int.TryParse(Convert.ToString(Request.Form["hdnRecipeIngridientsId" + i]), out recipe_ingredientsid);
            }


            //Get Ingridients.
            if (Request.Form["txtIngridients" + i] != null && !string.IsNullOrWhiteSpace(Request.Form["txtIngridients" + i]))
            {
                name = Convert.ToString(Request.Form["txtIngridients" + i]);
            }

            //Get Quantity.
            if (Request.Form["txtQuantity" + i] != null && !string.IsNullOrWhiteSpace(Request.Form["txtQuantity" + i]))
            {
                qty = Convert.ToString(Request.Form["txtQuantity" + i]);

                //Parse the string variable qty have valid interger value and store into Q (int) variable. Otherwise it will store 0.
                int.TryParse(qty, out Q);
            }

            //Get Unit Name.
            if (Request.Form["ddlUnit" + i] != null && !string.IsNullOrWhiteSpace(Request.Form["ddlUnit" + i]))
            {
                unit = Convert.ToString(Request.Form["ddlUnit" + i]);
            }

            if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(unit) && Q > 0)
            {
                var ingridientResult = (from ri in rdbEnty.recipe_ingredients
                                        join r in rdbEnty.recipes on ri.recipe_id equals r.id
                                        join ing in rdbEnty.ingredients on ri.ingredient_id equals ing.id
                                        where ri.recipe_id == recipeId && ri.id == recipe_ingredientsid
                                        select ing);

                //Update ingridient.
                IEnumerable <ingredient> ingredientEditList = ingridientResult.ToList();
                foreach (var ingredient in ingredientEditList)
                {
                    ingredient.name     = name;
                    ingredient.MemberId = MemberId;
                    rdbEnty.SaveChanges();
                }

                var recipe_ingridientResult = (from ri in rdbEnty.recipe_ingredients
                                               join r in rdbEnty.recipes on ri.recipe_id equals r.id
                                               join ing in rdbEnty.ingredients on ri.ingredient_id equals ing.id
                                               where ri.recipe_id == recipeId && ri.id == recipe_ingredientsid
                                               select ri);

                //Update recipe_ingridient.
                IEnumerable <recipe_ingredients> recipe_ingredientsEditList = recipe_ingridientResult.ToList();
                foreach (var recipe_ingredients in recipe_ingredientsEditList)
                {
                    recipe_ingredients.ingredient_id = ingredientEditList.ToList()[0].id;
                    recipe_ingredients.recipe_id     = recipeId;
                    recipe_ingredients.unit          = unit;
                    recipe_ingredients.quantity      = Q;
                    recipe_ingredients.MemberId      = MemberId;
                    rdbEnty.SaveChanges();
                }
            }
        }
    }