Пример #1
0
 private void PopulateAll()
 {
     foreach (var recipe in _prototypeManager.EnumeratePrototypes <ConstructionPrototype>())
     {
         RecipesList.Add(GetItem(recipe, RecipesList));
     }
 }
Пример #2
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"));
            }
        }
Пример #3
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);
                }
            }
        }
Пример #4
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"));
        }