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 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 ActionResult Create([Bind(Include = "id,firstname,lastname,username,password")] user user) { if (ModelState.IsValid) { db.users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "id,name,author,type,actualrecipe")] recipe recipe) { if (ModelState.IsValid) { db.recipes.Add(recipe); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(recipe)); }
public JsonResult addUser(user user) { using (re = new recipeEntities()) { var success = true; if (TryUpdateModel(user)) { re.users.Add(user); //Membership.CreateUser(user.name, user.password); try { //Membership.CreateUser(user.name, user.password, user.email); re.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } } else { success = false; } return(Json(new { success = success, id = user.id, user = user.getSerialize() }, JsonRequestBehavior.AllowGet)); } }
public JsonResult approvep(int id) { using (recipes = new recipeEntities()) { var pr = recipes.products.FirstOrDefault(p => p.id == id); pr.approved = true; recipes.SaveChanges(); return(Json(new { success = "success", product = pr.getSerialize() }, JsonRequestBehavior.AllowGet)); } }
public JsonResult approver(int id) { using (recipes = new recipeEntities()) { var rec = recipes.recipes.FirstOrDefault(r => r.id == id); rec.approved = true; recipes.SaveChanges(); return(Json(new { success = "success", recipe = rec.getSerialize() }, JsonRequestBehavior.AllowGet)); } }
public JsonResult user(int id) { using (recipes = new recipeEntities()) { bool ans = false; user user = recipes.users.FirstOrDefault(p => p.id == id); recipes.users.Remove(user); recipes.SaveChanges(); return(Json(new { success = ans }, JsonRequestBehavior.AllowGet)); } }
public JsonResult product(int id) { using (recipes = new recipeEntities()) { bool ans = false; product product = recipes.products.FirstOrDefault(p => p.id == id); recipes.products.Remove(product); recipes.SaveChanges(); return(Json(new { success = ans }, JsonRequestBehavior.AllowGet)); } }
public JsonResult recipe(int id) { using (recipes = new recipeEntities()) { bool ans = false; recipe recipe = recipes.recipes.FirstOrDefault(r => r.id == id); recipes.recipes.Remove(recipe); recipes.SaveChanges(); return(Json(new { success = ans }, JsonRequestBehavior.AllowGet)); } }
public JsonResult product(product p) { using (recipes = new recipeEntities()) { bool ans = false; if (ModelState.IsValid) { //recipes.Entry(p).State = EntityState.Modified; recipes.SaveChanges(); ans = true; } return(Json(new { success = ans, product = p }, JsonRequestBehavior.AllowGet)); } }
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)); } }