public ActionResult DeleteConfirmed(int?id) { IngredientsForRecipes ingredientsForRecipes = db.IngredientsForRecipes.Find(id); db.IngredientsForRecipes.Remove(ingredientsForRecipes); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ArbitraryId,RecipeId,IngredientName,Amount,Unit")] IngredientsForRecipes ingredientsForRecipes) { if (ModelState.IsValid) { db.Entry(ingredientsForRecipes).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RecipeId = new SelectList(db.Recipe, "Id", "title", ingredientsForRecipes.RecipeId); return(View(ingredientsForRecipes)); }
// GET: IngredientsForRecipes/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IngredientsForRecipes ingredientsForRecipes = db.IngredientsForRecipes.Find(id); if (ingredientsForRecipes == null) { return(HttpNotFound()); } return(View(ingredientsForRecipes)); }
// GET: IngredientsForRecipes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IngredientsForRecipes ingredientsForRecipes = db.IngredientsForRecipes.Find(id); if (ingredientsForRecipes == null) { return(HttpNotFound()); } ViewBag.RecipeId = new SelectList(db.Recipe, "Id", "title", ingredientsForRecipes.RecipeId); return(View(ingredientsForRecipes)); }
public void GetRecipeInfoCall(Recipe recipe) { string urlString = recipe.apiId.ToString() + "/information?includeNutrition=false"; var response = GetApiRequest(urlString); var result = response.Result.Body; JObject jobject = JObject.Parse(result); var ingredientInfo = jobject.SelectToken("extendedIngredients"); var stepInfo = jobject.SelectToken("analyzedInstructions"); List <string> ingredientsRetreived = new List <string>(); List <GetAnalyzedInstructionsStep> stepsRetreived = new List <GetAnalyzedInstructionsStep>(); foreach (var ingredient in ingredientInfo) { IngredientsForRecipes ingredientsFor = new IngredientsForRecipes { RecipeId = recipe.Id, IngredientName = ingredient.SelectToken("name").ToString(), Amount = (double)ingredient.SelectToken("amount"), Unit = ingredient.SelectToken("unit").ToString() }; _context.IngredientsForRecipes.Add(ingredientsFor); } GetAnalyzedInstructions[] rootObject = JsonConvert.DeserializeObject <GetAnalyzedInstructions[]>(stepInfo.ToString()); try { var root = rootObject[0]; foreach (var step in root.steps) { StepsForRecipe newStep = new StepsForRecipe { RecipeId = recipe.Id, StepNumber = step.number, StepDescription = step.step }; _context.StepsForRecipe.Add(newStep); } } catch (IndexOutOfRangeException) { Recipe ignoringRecipe = _context.Recipe.Find(recipe.Id); _context.Recipe.Remove(ignoringRecipe); } _context.SaveChanges(); }