Beispiel #1
0
 public IActionResult EditRecipe(int id)
 {
     Console.WriteLine("EDIT RECIPE");
     RecipesList.GetInstance().ActualRecipe = RecipesList.GetInstance().getRecipe(id);
     RecipesList.GetInstance().Recipes.RemoveAt(id);
     return(RedirectToAction("AddRecipe"));
 }
Beispiel #2
0
        public IActionResult list()
        {
            List <string> ret = new List <string>();

            List <Recipe>     shoppinglist      = RecipesList.GetInstance().ShoppingList;
            List <Ingredient> vectorIngredients = new List <Ingredient>();

            for (int i = 0; i < shoppinglist.Count; i++)
            {
                List <Ingredient> auxvec = new List <Ingredient>();

                auxvec = shoppinglist[i].RecIngredients1;

                for (int j = 0; j < auxvec.Count; j++)
                {
                    if (vectorIngredients.Count == 0)
                    {
                        vectorIngredients.Add(auxvec[j]);
                    }
                    else
                    {
                        int existIndex = -1;
                        for (int k = 0; k < vectorIngredients.Count; k++)
                        {
                            if (auxvec[j].IngName1 == vectorIngredients[k].IngName1 && auxvec[j].IngUnits1 == vectorIngredients[k].IngUnits1)
                            {
                                existIndex = k;
                            }
                        }
                        if (existIndex != -1)
                        {
                            decimal newValue = Math.Round(vectorIngredients[existIndex].IngQuantity1 + auxvec[j].IngQuantity1, 3);

                            vectorIngredients.RemoveAt(existIndex);

                            Ingredient aux = new Ingredient();
                            aux.IngName1     = auxvec[j].IngName1;
                            aux.IngUnits1    = auxvec[j].IngUnits1;
                            aux.IngQuantity1 = newValue;

                            vectorIngredients.Add(aux);
                        }
                        else
                        {
                            vectorIngredients.Add(auxvec[j]);
                        }
                    }
                }
            }
            for (int l = 0; l < vectorIngredients.Count; l++)
            {
                Ingredient auxIngredient = vectorIngredients[l];
                string     auxString     = auxIngredient.IngName1 + ": " + (float)auxIngredient.IngQuantity1 + " " + auxIngredient.IngUnits1;
                ret.Add(auxString);
            }
            string result = string.Join("\n", ret);

            return(Content(result));
        }
Beispiel #3
0
        public IActionResult DeleteIngredient(RecipeIngModel aux)
        {
            var number = Request.Form["select1"];
            int index  = Int32.Parse(number);

            RecipesList.GetInstance().ActualRecipe.deleteingredient(index);

            return(RedirectToAction("AddRecipe"));
        }
Beispiel #4
0
        public IActionResult AddToShoppingList(RecipeIngModel aux)

        {
            string number = Request.Form["select2"];
            int    index  = Int32.Parse(number);
            Recipe temp   = RecipesList.GetInstance().getRecipe(index);

            RecipesList.GetInstance().AddToShopping(temp);

            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        // GET
        public IActionResult AddRecipe()
        {
            RecipesList temp = RecipesList.GetInstance();

            if (temp.ActualRecipe.RecName1 != "")
            {
                @ViewData["name"] = temp.ActualRecipe.RecName1;
            }

            if (temp.ActualRecipe.RecDescription1.Count != 0)
            {
                string result = string.Join("\n", temp.ActualRecipe.RecDescription1);
                @ViewData["description"] = result;
            }

            return(View());
        }
Beispiel #6
0
        public IActionResult AddRecipeToList()
        {
            //DEPRECATED
            RecipesList temp = RecipesList.GetInstance();


            if (temp.ActualRecipe == null || temp.ActualRecipe.RecDescription1.Count == 0 ||
                temp.ActualRecipe.RecName1 == "" || temp.ActualRecipe.RecIngredients1.Count == 0)
            {
                return(RedirectToAction("AddRecipe"));
            }
            else
            {
                temp.Add();

                return(RedirectToAction("ReloadIndex", "Home"));
            }
        }
Beispiel #7
0
        public void write()
        {
            RecipesList   reci    = RecipesList.GetInstance();
            List <Recipe> recipes = reci.Recipes;

            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.Formatting = Formatting.Indented;

                writer.WriteStartObject();
                foreach (var recipe in recipes)
                {
                    writer.WritePropertyName(recipe.RecName1);
                    writer.WriteStartObject();
                    writer.WritePropertyName("recipe");
                    writer.WriteStartArray();
                    foreach (var desc in recipe.RecDescription1)
                    {
                        writer.WriteValue(desc);
                    }
                    writer.WriteEnd();
                    foreach (var ing in recipe.RecIngredients1)
                    {
                        writer.WritePropertyName(ing.IngName1);
                        writer.WriteValue(ing.IngQuantity1 + " " + ing.IngUnits1);
                    }

                    writer.WriteEnd();
                }

                writer.WriteEnd();
                //   writer.WriteEndObject();
            }
            System.IO.File.WriteAllText("recipes.json", sb.ToString());

            sw.Close();
        }
Beispiel #8
0
        public IActionResult EditOrDeleteRecipe(string answer)
        {
            string number = Request.Form["select2"];

            switch (answer)
            {
            case "Edit Recipe":
                if (number != null)
                {
                    return(RedirectToAction("EditRecipe", "AddRecipe", new { id = number }));
                }
                break;

            case "Delete Recipe":
                if (number != null)
                {
                    int index = Int32.Parse(number);
                    RecipesList.GetInstance().Recipes.RemoveAt(index);
                    return(RedirectToAction("ReloadIndex"));
                }
                break;
            }
            return(Redirect("/Home"));
        }
Beispiel #9
0
 // GET
 public IActionResult ShoppingList()
 {
     RecipesList.GetInstance().ShoppingList = new List <Recipe>();
     return(View());
 }
Beispiel #10
0
        public void read()
        {
            RecipesList del = RecipesList.GetInstance();

            del.Empty();
            using (StreamReader r = new StreamReader("recipes.json"))
            {
                string json = r.ReadToEnd();


                JsonTextReader reader       = new JsonTextReader(new StringReader(json));
                JObject        googleSearch = JObject.Parse(json);

                List <JToken> results = googleSearch.Children().ToList();

                List <Recipe> searchResults = new List <Recipe>();


                foreach (JToken result in results)
                {
                    JProperty jProperty    = result.ToObject <JProperty>();
                    string    propertyName = jProperty.Name;

                    Recipe temp = new Recipe();
                    temp.RecName1 = propertyName;


                    List <JToken> ingredients = result.Children().Children().ToList();
                    foreach (JToken ingredientAndRecipeDes in ingredients)
                    {
                        JProperty jProperty2 = ingredientAndRecipeDes.ToObject <JProperty>();
                        string    ingName    = jProperty2.Name;
                        if (ingName == "recipe")
                        {
                            string[] splitDescription = ingredientAndRecipeDes.ToString().Split(':');


                            string[]      unitsAndQuantity = splitDescription[1].Split('"');
                            List <string> descriptionList  = new List <string>();

                            foreach (var word in unitsAndQuantity)
                            {
                                if (word != "" && word != ",\n  " && word != " [\n  " && word != "\n]")
                                {
                                    descriptionList.Add(word);
                                }
                            }
                            temp.RecDescription1 = descriptionList;
                        }
                        else
                        {
                            string[] splitUnitsAndQuantity = ingredientAndRecipeDes.ToString().Split('"');
                            string[] unitsAndQuantity      = splitUnitsAndQuantity[3].Split(' ');
                            decimal  quantity = decimal.Parse(unitsAndQuantity[0]);
                            string   units    = "";

                            for (int i = 1; i < unitsAndQuantity.Length; i++)
                            {
                                units += unitsAndQuantity[i];
                            }

                            temp.addRecIngredient(ingName, quantity, units);
                        }
                    }
                    //  temp.printRecipe();
                    RecipesList recipes = RecipesList.GetInstance();
                    recipes.Add(temp);
                }
            }
        }
Beispiel #11
0
        public IActionResult AddIngredient(RecipeIngModel aux, string answer)

        {
            RecipesList temp = RecipesList.GetInstance();

            switch (answer)
            {
            case "Add Ingredient":

                Ingredient obj = aux.Ingredient;


                if (obj.IngName1 != "" && obj.IngUnits1 != "")
                {
                    Console.WriteLine("INGREDIENT ADDED");
                    temp.ActualRecipe.addRecIngredient(obj.IngName1, obj.IngQuantity1, obj.IngUnits1);
                }

                if (aux.Description1 != null)
                {
                    @ViewData["description"] = aux.Description1;
                    List <String> des = aux.Description1.Split("\r\n").ToList();
                    temp.ActualRecipe.RecDescription1 = des;
                }
                else if (temp.ActualRecipe.RecDescription1.Count != 0)
                {
                    string result = string.Join("\n", temp.ActualRecipe.RecDescription1);
                    @ViewData["description"] = result;
                }

                {
                    @ViewData["description"] = "";
                }
                if (aux.RecName1 != null)
                {
                    temp.ActualRecipe.RecName1 = aux.RecName1;
                    @ViewData["name"]          = aux.RecName1;
                }
                else if (temp.ActualRecipe.RecName1 != "")
                {
                    @ViewData["name"] = temp.ActualRecipe.RecName1;
                }

                {
                    @ViewData["name"] = "";
                }


                return(RedirectToAction("AddRecipe"));

                break;

            case "Add Recipe":
                if (aux.RecName1 != null)
                {
                    temp.ActualRecipe.RecName1 = aux.RecName1;
                }

                if (aux.Description1 != null)
                {
                    List <String> des = aux.Description1.Split("\r\n").ToList();
                    temp.ActualRecipe.RecDescription1 = des;
                }


                if (temp.ActualRecipe == null || temp.ActualRecipe.RecDescription1.Count == 0 ||
                    temp.ActualRecipe.RecName1 == "" || temp.ActualRecipe.RecIngredients1.Count == 0)
                {
                    Console.WriteLine("PLEASE ENTER ALL THE DATA");
                    return(RedirectToAction("AddRecipe"));
                }
                else
                {
                    Console.WriteLine("RECIPE ADDED");
                    temp.Add();

                    return(RedirectToAction("ReloadIndex", "Home"));
                }


                break;
            }
            return(RedirectToAction("AddRecipe"));
        }
Beispiel #12
0
 public IActionResult NewRecipe()
 {
     Console.WriteLine("NEW RECIPE");
     RecipesList.GetInstance().ActualRecipe = new Recipe();
     return(RedirectToAction("AddRecipe"));
 }