private void PopulateAll() { foreach (var recipe in _prototypeManager.EnumeratePrototypes <ConstructionPrototype>()) { RecipesList.Add(GetItem(recipe, RecipesList)); } }
public void EachItem() { Client listClient = new ClientMock(MockResponse.RecipesList); foreach (Recipe item in RecipesList.EachItem(listClient)) { Assert.That(listClient, Is.SameAs(item.record.RecordClient)); Assert.AreEqual(item.record.RecordEndpoint, "ingest_recipes"); } var per_page = "1"; var query = new Dictionary <string, string>() { { "per_page", per_page } }; int countItem = 0; foreach (Recipe item in RecipesList.EachItem(query, listClient)) { countItem++; } Assert.AreEqual(countItem.ToString(), per_page); }
public IActionResult EditRecipe(int id) { Console.WriteLine("EDIT RECIPE"); RecipesList.GetInstance().ActualRecipe = RecipesList.GetInstance().getRecipe(id); RecipesList.GetInstance().Recipes.RemoveAt(id); return(RedirectToAction("AddRecipe")); }
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)); }
public IActionResult DeleteIngredient(RecipeIngModel aux) { var number = Request.Form["select1"]; int index = Int32.Parse(number); RecipesList.GetInstance().ActualRecipe.deleteingredient(index); return(RedirectToAction("AddRecipe")); }
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")); }
public ActionResult InitialRec(string search) { string searchstr = null; var gender = Request.Form["option"]; var age = Request.Form["age"]; Dictionary <string, string> recipesMap = new Dictionary <string, string>(); if (search == null) { searchstr = "http://food2fork.com/api/search?key=b18c7f80205225f5a6c3585901b06092&q=chicken"; } else { searchstr = "http://food2fork.com/api/search?key=b18c7f80205225f5a6c3585901b06092&q=" + search; } var request = (HttpWebRequest)WebRequest.Create(searchstr); var response = (HttpWebResponse)request.GetResponse(); string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); RecipesRootObject rb = JsonConvert.DeserializeObject <RecipesRootObject>(responseString); RecipesList recipesList = new RecipesList(); recipesList.Rlist = new List <SpecificRecipe>(); int number = 0; foreach (Recipes recipes in rb.recipes) { if (!recipesMap.ContainsKey(recipes.title)) { SpecificRecipe specificrecipe = new SpecificRecipe(); specificrecipe.title = recipes.title; specificrecipe.ImageUrl = recipes.image_url; specificrecipe.Id = recipes.recipe_id; specificrecipe.Ingredients = GetIngredient(recipes.recipe_id); string[] searchArray = Regex.Split(specificrecipe.Ingredients, ",", RegexOptions.IgnoreCase); specificrecipe.Calorie = getNutrition(searchArray, recipes.recipe_id); recipesList.Rlist.Add(specificrecipe); } number++; if (number == 9) { break; } } if (search == null) { return(View("MenuList", recipesList)); } else { return(PartialView("Recipeslist", recipesList)); } }
// 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()); }
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")); } }
public void NewRecipesList() { var list = new RecipesList(); Assert.AreEqual(list.records.RecordEndpoint, "ingest_recipes"); Assert.IsInstanceOf <List <Record> > (list.records.List); Assert.IsInstanceOf <List <Recipe> > (list.Page); var client = new ClientMock(MockResponse.RecipesList); list = new RecipesList(client); Assert.AreEqual(list.records.RecordEndpoint, "ingest_recipes"); Assert.IsInstanceOf <List <Record> > (list.records.List); Assert.IsInstanceOf <List <Recipe> > (list.Page); Assert.IsInstanceOf <Client> (list.records.RecordClient); }
public void Paginate() { var list = RecipesList.Paginate(new ClientMock(MockResponse.RecipesList)); var listClient = list.records.RecordClient; Assert.AreEqual(list.records.RecordEndpoint, "ingest_recipes"); foreach (var item in list.Page) { Assert.AreEqual(item.record.RecordEndpoint, "ingest_recipes"); } var per_page = "1"; var query = new Dictionary <string, string>() { { "per_page", per_page } }; var list2 = RecipesList.Paginate(query, new ClientMock(MockResponse.RecipesList)); var countItem = 0; foreach (var item in list2.Page) { countItem++; } Assert.AreEqual(countItem.ToString(), per_page); list = RecipesList.Paginate(new ClientMock(MockResponse.RecordPaginate)); Assert.IsTrue(list.Next()); Assert.IsTrue(list.Prevous()); Assert.IsTrue(list.First()); Assert.IsTrue(list.Last()); list = RecipesList.Paginate(new ClientMock(MockResponse.RecordPaginateEmpty)); Assert.IsFalse(list.Next()); Assert.IsFalse(list.Prevous()); Assert.IsFalse(list.First()); Assert.IsFalse(list.Last()); }
public ActionResult ChangeRecipes(string search) { string searchstr = null; var gender = Request.Form["option"]; var age = Request.Form["age"]; Dictionary <string, string> recipesMap = new Dictionary <string, string>(); if (search == null) { searchstr = "http://food2fork.com/api/search?key=7980b1abc6ccc9eb785e5aee4e972120&q=chinese"; } else { searchstr = "http://food2fork.com/api/search?key=7980b1abc6ccc9eb785e5aee4e972120&q=" + search; } var request = (HttpWebRequest)WebRequest.Create(searchstr); var response = (HttpWebResponse)request.GetResponse(); string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); RecipesRootObject rb = JsonConvert.DeserializeObject <RecipesRootObject>(responseString); RecipesList recipesList = new RecipesList(); recipesList.Rlist = new List <Recipe>(); int number = 0; foreach (Recipes recipes in rb.recipes) { if (!recipesMap.ContainsKey(recipes.title)) { Recipe recipe = new Recipe(); recipe.title = recipes.title; recipe.ImageUrl = recipes.image_url; recipesList.Rlist.Add(recipe); } number++; if (number == 18) { break; } } // ViewData["data"] = recipesMap; return(PartialView("Recipeslist", recipesList)); }
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(); }
async private void AddRecipeButton_Clicked(object sender, RoutedEventArgs e) { try { if (addRecipeName.Text != "") { RecipesList recipesList = new RecipesList { recipeName = addRecipeName.Text, userID = MainPage.SessionUser.sessionUsername, isChecked = (bool)recipeShareable.IsChecked, ingredient1 = addingredient1.Text, ingredient2 = addingredient2.Text, ingredient3 = addingredient3.Text, ingredient4 = addingredient4.Text, ingredient5 = addingredient5.Text, ingredient6 = addingredient6.Text, ingredient7 = addingredient7.Text, }; await App.MobileService.GetTable <RecipesList>().InsertAsync(recipesList); var dialog = new MessageDialog("Recipe added successfully!"); await dialog.ShowAsync(); ClearAdd(); } else { var dialog = new MessageDialog("Please enter recipe name."); await dialog.ShowAsync(); } } catch (Exception ex) { var dialog = new MessageDialog("An Error Occured: " + ex.Message); await dialog.ShowAsync(); } }
async private void EditRecipeButton_Clicked(object sender, RoutedEventArgs e) { try { if (editRecipeName.SelectedValue != null) { RecipesList editRecipe = new RecipesList { Id = editHiddenID.Text, userID = MainPage.SessionUser.sessionUsername, recipeName = editHiddenRecipeName.Text, isChecked = (bool)editRecipeShareable.IsChecked, ingredient1 = editingredient1.Text, ingredient2 = editingredient2.Text, ingredient3 = editingredient3.Text, ingredient4 = editingredient4.Text, ingredient5 = editingredient5.Text, ingredient6 = editingredient6.Text, ingredient7 = editingredient7.Text }; await recipesList.UpdateAsync(editRecipe); var dialog = new MessageDialog("Recipe edited successfully!"); await dialog.ShowAsync(); ClearUpdate(); } else { var dialog = new MessageDialog("Recipe not selected for edit."); await dialog.ShowAsync(); } } catch (Exception ex) { var dialog = new MessageDialog("An Error Occured: " + ex.Message); await dialog.ShowAsync(); } }
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")); }
public IActionResult NewRecipe() { Console.WriteLine("NEW RECIPE"); RecipesList.GetInstance().ActualRecipe = new Recipe(); return(RedirectToAction("AddRecipe")); }
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")); }
// GET public IActionResult ShoppingList() { RecipesList.GetInstance().ShoppingList = new List <Recipe>(); return(View()); }
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); } } }
public void UpdateRecipesList(RecipesList _recipesList) { recipes = (from recipe in _recipesList.recipes select recipe).ToList(); numerableRecipes = _recipesList.numerable; }
public static void ReadingIngestRecipesList(string id, string token) { try { Console.WriteLine("--EachItem()--"); foreach (Recipe item in RecipesList.EachItem()) { Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]); } Console.WriteLine("--EachItem(query)--"); Dictionary <string, string> query = new Dictionary <string, string>() { { "sort", "id" }, { "order", "desc" }, { "per_page", "2" } }; Client client = new Client() { CfgClientId = id, CfgAuthToken = token }; foreach (var item in RecipesList.EachItem(query, client)) { Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]); } Console.WriteLine("--Paginate--"); var items1 = RecipesList.Paginate(); foreach (var item in items1.Page) { Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]); } Console.WriteLine("--Paginate(query)--"); var items2 = RecipesList.Paginate(query, new Client()); Console.WriteLine("--Paginate(query)--Initial-First--"); foreach (var item in items2.Page) { Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]); } while (items2.Next()) { Console.WriteLine("--Paginate(query)--Next--"); foreach (var item in items2.Page) { Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]); } } Console.WriteLine("--Paginate(query)--Previous--"); items2.Prevous(); foreach (var item in items2.Page) { Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]); } Console.WriteLine("--Paginate(query)--Last--"); items2.Last(); foreach (var item in items2.Page) { Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]); } Console.WriteLine("--Paginate(query)--First--"); items2.First(); foreach (var item in items2.Page) { Console.WriteLine("Id: " + item["id"] + " Name: " + item["name"]); } } catch (VzaarApiException ve) { Console.Write("!!!!!!!!! EXCEPTION !!!!!!!!!"); Console.WriteLine(ve.Message); } catch (Exception e) { Console.Write("!!!!!!!!! EXCEPTION !!!!!!!!!"); Console.WriteLine(e.Message); if (e is AggregateException) { AggregateException ae = (AggregateException)e; var flatten = ae.Flatten(); foreach (var fe in flatten.InnerExceptions) { if (fe is VzaarApiException) { Console.WriteLine(fe.Message); } } } } }
public void RecordsListValidation() { var expected = "Missing 'data' token"; try { var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingData)); //if the exception is not thrown, the below assert fails bool assert = true; Assert.IsFalse(assert); } catch (VzaarApiException ve) { StringAssert.Contains(expected, ve.Message); } catch (Exception e) { if (e is AggregateException) { AggregateException ae = (AggregateException)e; var flatten = ae.Flatten(); foreach (var fe in flatten.InnerExceptions) { if (fe is VzaarApiException) { StringAssert.Contains(expected, fe.Message); } } } } expected = "'data' value is not array"; try { var list = RecipesList.Paginate(new ClientMock(MockResponse.DataNotArray)); //if the exception is not thrown, the below assert fails bool assert = true; Assert.IsFalse(assert); } catch (VzaarApiException ve) { StringAssert.Contains(expected, ve.Message); } catch (Exception e) { if (e is AggregateException) { AggregateException ae = (AggregateException)e; var flatten = ae.Flatten(); foreach (var fe in flatten.InnerExceptions) { if (fe is VzaarApiException) { StringAssert.Contains(expected, fe.Message); } } } } expected = "Missing 'meta' token"; try { var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingMeta)); //if the exception is not thrown, the below assert fails bool assert = true; Assert.IsFalse(assert); } catch (VzaarApiException ve) { StringAssert.Contains(expected, ve.Message); } catch (Exception e) { if (e is AggregateException) { AggregateException ae = (AggregateException)e; var flatten = ae.Flatten(); foreach (var fe in flatten.InnerExceptions) { if (fe is VzaarApiException) { StringAssert.Contains(expected, fe.Message); } } } } expected = "Missing 'links' token"; try { var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingLinks)); //if the exception is not thrown, the below assert fails bool assert = true; Assert.IsFalse(assert); } catch (VzaarApiException ve) { StringAssert.Contains(expected, ve.Message); } catch (Exception e) { if (e is AggregateException) { AggregateException ae = (AggregateException)e; var flatten = ae.Flatten(); foreach (var fe in flatten.InnerExceptions) { if (fe is VzaarApiException) { StringAssert.Contains(expected, fe.Message); } } } } expected = "Missing 'next' token"; try { var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingNext)); //if the exception is not thrown, the below assert fails bool assert = true; Assert.IsFalse(assert); } catch (VzaarApiException ve) { StringAssert.Contains(expected, ve.Message); } catch (Exception e) { if (e is AggregateException) { AggregateException ae = (AggregateException)e; var flatten = ae.Flatten(); foreach (var fe in flatten.InnerExceptions) { if (fe is VzaarApiException) { StringAssert.Contains(expected, fe.Message); } } } } expected = "Missing 'previous' token"; try { var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingPrevious)); //if the exception is not thrown, the below assert fails bool assert = true; Assert.IsFalse(assert); } catch (VzaarApiException ve) { StringAssert.Contains(expected, ve.Message); } catch (Exception e) { if (e is AggregateException) { AggregateException ae = (AggregateException)e; var flatten = ae.Flatten(); foreach (var fe in flatten.InnerExceptions) { if (fe is VzaarApiException) { StringAssert.Contains(expected, fe.Message); } } } } expected = "Missing 'last' token"; try { var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingLast)); //if the exception is not thrown, the below assert fails bool assert = true; Assert.IsFalse(assert); } catch (VzaarApiException ve) { StringAssert.Contains(expected, ve.Message); } catch (Exception e) { if (e is AggregateException) { AggregateException ae = (AggregateException)e; var flatten = ae.Flatten(); foreach (var fe in flatten.InnerExceptions) { if (fe is VzaarApiException) { StringAssert.Contains(expected, fe.Message); } } } } expected = "Missing 'first' token"; try { var list = RecipesList.Paginate(new ClientMock(MockResponse.MissingFirst)); //if the exception is not thrown, the below assert fails bool assert = true; Assert.IsFalse(assert); } catch (VzaarApiException ve) { StringAssert.Contains(expected, ve.Message); } catch (Exception e) { if (e is AggregateException) { AggregateException ae = (AggregateException)e; var flatten = ae.Flatten(); foreach (var fe in flatten.InnerExceptions) { if (fe is VzaarApiException) { StringAssert.Contains(expected, fe.Message); } } } } } // end