private void MakeUpdateToRecipe()
        {
            var recipe = (from n in listInput
                          where n.id == Convert.ToInt32(selectedRecipe.id)
                          select n).FirstOrDefault();

            listInput.Remove(recipe);
            listInput.Add(selectedRecipe);
            MyStorage.WriteXml <ObservableCollection <Recipe> >(listInput, "InputData.xml");
        }
        private void StarImage_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var recipeId  = ((((sender as TextBlock).Parent as StackPanel).Parent as StackPanel).Children[0] as TextBlock).Text;
            var listInput = MyStorage.ReadXml <List <Recipe> >("InputData.xml");
            var recipe    = (from n in listInput
                             where n.id == Convert.ToInt32(recipeId)
                             select n).FirstOrDefault();

            recipe.isFavorite = recipe.isFavorite == true ? false : true;
            MyStorage.WriteXml <List <Recipe> >(listInput, "InputData.xml");
            GetRecipes();
        }
        private int SaveRecipe(bool fromSave)
        {
            if (Tbx_recipeName.Text != "" || Tbx_recipeDescription.Text.Trim() != "" || Tbx_instructions.Text.Trim() != "" || Tbx_image.Text != "" || Lbx_ingredients.Items.Count > 0)
            {
                storeData = true;
            }
            else
            {
                storeData = false;
            }

            if (storeData)
            {
                if (Tbx_recipeName.Text != "")
                {
                    string imagePath = Tbx_image.Text;
                    string destPath  = imagePath;
                    if (imagePath != "")
                    {
                        string[] parts = imagePath.Split('\\');
                        if (parts[0] != "")
                        {
                            string imageName = parts[parts.Length - 1];

                            destPath = @"\Images\" + imageName;
                            string currentDirectory = System.Environment.CurrentDirectory;
                            if (currentDirectory.EndsWith("\\bin\\Debug"))
                            {
                                int index = currentDirectory.IndexOf("\\bin\\Debug");
                                currentDirectory = currentDirectory.Substring(0, index);
                            }
                            File.Copy(imagePath, currentDirectory + destPath, true);
                        }
                        else
                        {
                            destPath = imagePath;
                        }
                    }
                    if (!isEdit)
                    {
                        var id = recipes.Max(m => m.id);
                        recipes.Add(new Recipe
                        {
                            isMyRecipe          = true,
                            name                = Tbx_recipeName.Text,
                            description         = Tbx_recipeDescription.Text,
                            id                  = id + 1,
                            timeRequiredHours   = Cbx_hours.SelectedValue.ToString(),
                            timeRequiredMinutes = Cbx_minutes.SelectedValue.ToString(),
                            servings            = Cbx_servings.SelectedValue.ToString(),
                            instruction         = Tbx_instructions.Text,
                            ingredients         = recipeIngredients.ToList(),
                            isFavorite          = Cbx_markFavorite.IsChecked.GetValueOrDefault(),
                            image               = imagePath == "" ? @"\Images\noimage.jpg" : destPath
                        });
                        var recipeList = recipes.ToList();
                        MyStorage.WriteXml <List <Recipe> >(recipeList, "InputData.xml");
                        MessageBox.Show("Your recipe has been added to the cookbook.");
                    }
                    else
                    {
                        var listInput = MyStorage.ReadXml <List <Recipe> >("InputData.xml");
                        var recipe    = (from n in listInput
                                         where n.id == Convert.ToInt32(selectedRecipe.id)
                                         select n).FirstOrDefault();
                        selectedRecipe.ingredients = recipeIngredients.ToList();
                        selectedRecipe.image       = destPath;
                        listInput.Remove(recipe);
                        listInput.Add(selectedRecipe);
                        MyStorage.WriteXml <List <Recipe> >(listInput, "InputData.xml");
                    }
                    return(1);
                }
                else
                {
                    if (!fromSave)
                    {
                        MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("You need to enter a recipe name to save the recipe. Click yes to enter the name.", "Save recipe confirmation", System.Windows.MessageBoxButton.YesNo);
                        if (messageBoxResult == MessageBoxResult.No || messageBoxResult == MessageBoxResult.Cancel || messageBoxResult == MessageBoxResult.None)
                        {
                            return(1);
                        }
                        else if (messageBoxResult == MessageBoxResult.Yes)
                        {
                            Tbx_recipeName.Focus();
                            return(0);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please enter a recipe name to save the recipe.", ":|", MessageBoxButton.OK, MessageBoxImage.Error);
                        Tbx_recipeName.Focus();
                        return(0);
                    }
                }
            }
            return(1);
        }
        private void CreateXMLData()
        {
            #region recipes
            List <Recipe> recipes = new List <Recipe>();
            recipes = new List <Recipe> {
                new Recipe
                {
                    id           = 1,
                    name         = "Potato Curry",
                    description  = "A simple and easy-to-make potato curry.",
                    servings     = "4",
                    timeRequired = "00:30",
                    instruction  = @"1.	Add the coconut oil to large skillet on medium heat. Add minced garlic.
                            2.	Once garlic is fragrant, add diced onion and cook until starting to turn translucent, about 5 minutes.
                            3.	Add coconut milk, diced tomatoes, ginger, maple syrup, and spices. Stir to combine.
                            4.	Bring to a low simmer and add potatoes.
                            5.	Cover and let simmer on low/medium until potatoes are softened, 10 - 15 minutes.
                            6.	Add frozen peas, stir, and let sit for 5 minutes.
                            7.	Stir again and serve.
                            ",
                    ingredients  = new List <RecipeIngredient>
                    {
                        new RecipeIngredient {
                            ingredientId   = 1,
                            ingredientName = "Potato",
                            ingredientType = "solid",
                            quantity       = "250",
                            measure        = "gram(s)",
                            recipeId       = 0
                        },
                        new RecipeIngredient {
                            ingredientId   = 2,
                            ingredientName = "Coconut oil",
                            ingredientType = "cream",
                            quantity       = "1",
                            measure        = "tablespoon(s)"
                        },
                        new RecipeIngredient {
                            ingredientId   = 3,
                            ingredientName = "Onion(s)",
                            ingredientType = "solid",
                            quantity       = "200",
                            measure        = "gram(s)"
                        },
                        new RecipeIngredient {
                            ingredientId   = 4,
                            ingredientName = "Tomato(s)",
                            ingredientType = "solid",
                            quantity       = "200",
                            measure        = "gram(s)"
                        },
                        new RecipeIngredient {
                            ingredientId   = 5,
                            ingredientName = "Coconut milk",
                            ingredientType = "solid",
                            quantity       = "200",
                            measure        = "ml"
                        },
                        new RecipeIngredient {
                            ingredientId   = 6,
                            ingredientName = "Curry powder",
                            ingredientType = "spice",
                            quantity       = "200",
                            measure        = "ml"
                        },
                        new RecipeIngredient {
                            ingredientId   = 7,
                            ingredientName = "Turmeric",
                            ingredientType = "spice",
                            quantity       = "200",
                            measure        = "ml"
                        },
                        new RecipeIngredient {
                            ingredientId   = 8,
                            ingredientName = "Salt",
                            ingredientType = "spice",
                            quantity       = "1",
                            measure        = "teaspoon(s)"
                        },
                        new RecipeIngredient {
                            ingredientId   = 9,
                            ingredientName = "Chilli powder",
                            ingredientType = "spice",
                            quantity       = "1",
                            measure        = "teaspoon(s)"
                        },
                        new RecipeIngredient {
                            ingredientId   = 10,
                            ingredientName = "Curry powder",
                            ingredientType = "spice",
                            quantity       = "1",
                            measure        = "teaspoon(s)"
                        },
                        new RecipeIngredient {
                            ingredientId   = 11,
                            ingredientName = "Garlic powder",
                            ingredientType = "spice",
                            quantity       = "1",
                            measure        = "teaspoon(s)"
                        },
                        new RecipeIngredient {
                            ingredientId   = 12,
                            ingredientName = "Ginger powder",
                            ingredientType = "spice",
                            quantity       = "1",
                            measure        = "teaspoon(s)"
                        }
                    },
                    isMyRecipe = false,
                    isFavorite = false,
                    image      = @"Images\easy-potato-curry-1.jpg",
                },
                new Recipe
                {
                    id           = 2,
                    name         = "Oven-Roasted Potatoes",
                    description  = "A side dish that goes along with roasted chicken, lamb chops and almost anything!",
                    servings     = "4",
                    timeRequired = "00:30",
                    instruction  = @"1.    Heat oven to 425°F. In an ungreased 15x10x1-inch pan, mix all ingredients; spread evenly.
                            2.  Roast uncovered 25 to 35 minutes, stirring occasionally, until potatoes are tender and browned.",
                    ingredients  = new List <RecipeIngredient>
                    {
                        new RecipeIngredient {
                            ingredientId   = 1,
                            ingredientName = "Potato",
                            ingredientType = "solid",
                            quantity       = "250",
                            measure        = "gram(s)",
                            recipeId       = 0
                        },
                        new RecipeIngredient {
                            ingredientId   = 2,
                            ingredientName = "Vegetable or olive oil",
                            ingredientType = "cream",
                            quantity       = "2",
                            measure        = "tablespoon(s)"
                        },
                        new RecipeIngredient {
                            ingredientId   = 3,
                            ingredientName = "Rosemary leaves",
                            ingredientType = "spice",
                            quantity       = "1",
                            measure        = "teaspoon(s)"
                        },
                        new RecipeIngredient {
                            ingredientId   = 4,
                            ingredientName = "Salt",
                            ingredientType = "spice",
                            quantity       = "0.5",
                            measure        = "teaspoon(s)"
                        },
                        new RecipeIngredient {
                            ingredientId   = 5,
                            ingredientName = "Pepper powder",
                            ingredientType = "spice",
                            quantity       = "0.5",
                            measure        = "teaspoon(s)"
                        }
                    },
                    isMyRecipe = false,
                    isFavorite = false,
                    image      = @"",
                }
            };
            MyStorage.WriteXml <List <Recipe> >(recipes, "RecipeData.xml");
            #endregion recipes

            #region ingredient

            List <Ingredient> ingredient = new List <Ingredient>();
            ingredient = new List <Ingredient> {
                new Ingredient
                {
                    id   = 1,
                    name = "Potato",
                    type = "solid"
                },
                new Ingredient
                {
                    id   = 2,
                    name = "Coconut oil",
                    type = "creamy"
                },
                new Ingredient
                {
                    id   = 3,
                    name = "Onion",
                    type = "solid"
                },
                new Ingredient
                {
                    id   = 4,
                    name = "Tomato",
                    type = "solid"
                },
                new Ingredient
                {
                    id   = 5,
                    name = "Rosemary leaves",
                    type = "spice"
                },
                new Ingredient
                {
                    id   = 6,
                    name = "Salt",
                    type = "spice"
                },
                new Ingredient
                {
                    id   = 7,
                    name = "Pepper powder",
                    type = "spice"
                },
                new Ingredient
                {
                    id   = 8,
                    name = "Coconut milk",
                    type = "creamy"
                },
                new Ingredient
                {
                    id   = 9,
                    name = "Curry powder",
                    type = "spice"
                },
                new Ingredient
                {
                    id   = 10,
                    name = "Turmeric",
                    type = "spice"
                },
                new Ingredient
                {
                    id   = 11,
                    name = "Chilli powder",
                    type = "spice"
                },
                new Ingredient
                {
                    id   = 12,
                    name = "Garlic powder",
                    type = "spice"
                },
                new Ingredient
                {
                    id   = 13,
                    name = "Ginger powder",
                    type = "spice"
                },
                new Ingredient
                {
                    id   = 14,
                    name = "Olive oil",
                    type = "creamy"
                },
                new Ingredient
                {
                    id   = 15,
                    name = "Vegetable oil",
                    type = "creamy"
                },
                new Ingredient
                {
                    id   = 16,
                    name = "Sugar",
                    type = "creamy"
                },
                new Ingredient
                {
                    id   = 17,
                    name = "Chicken",
                    type = "solid"
                }
            };
            MyStorage.WriteXml <List <Ingredient> >(ingredient, "IngredientData.xml");
            #endregion ingredient
        }