public JsonResult addProduct(Product addProduct, NutritonalValue_for_product[] nutritionals) { using (recipes = new recipeEntities()) { try { recipes.SaveChanges(); } catch (DbEntityValidationException ex) { catch_errors(ex); } product p = addProduct.getEntity(); var pr = recipes.Entry(p); pr.State = EntityState.Added; List <products_in_nutritional_value> nutritionalsVal = nutritionals.Select(n => n.getEntity()).ToList(); pr.Entity.products_in_nutritional_value = nutritionalsVal; try { recipes.SaveChanges(); } catch (DbEntityValidationException ex) { catch_errors(ex); } return(Json(new { success = true, p = p.getSerialize() })); } }
public JsonResult addRecipe(recipe recipe, equipment_in_recipe[] equipments, products_in_recipe[] products_in_recipe) { using (recipes = new recipeEntities()) { try { recipes.SaveChanges(); } catch (DbEntityValidationException ex) { catch_errors(ex); // Retrieve the error messages as a list of strings. } var r = recipes.Entry(recipe); r.State = EntityState.Added; r.Entity.equipment_in_recipe = equipments; r.Entity.isApproved(); r.Entity.products_in_recipe = products_in_recipe; try { recipes.SaveChanges(); } catch (DbEntityValidationException ex) { catch_errors(ex); // Retrieve the error messages as a list of strings. } return(Json(new { success = true, recipe = recipe.getSerialize() })); } }
public ActionResult Edit([Bind(Include = "id,firstname,lastname,username,password")] user user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Edit([Bind(Include = "id,name,author,type,actualrecipe")] recipe recipe) { if (ModelState.IsValid) { db.Entry(recipe).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(recipe)); }
public JsonResult recipe(recipe r) { using (recipes = new recipeEntities()) { bool ans = false; if (ModelState.IsValid) { var rec = recipes.Entry(r); //rec.State = EntityState.Modified; recipes.SaveChanges(); ans = true; } return(Json(new { success = ans, recipe = r }, JsonRequestBehavior.AllowGet)); } }