Esempio n. 1
0
 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() }));
     }
 }
Esempio n. 2
0
 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() }));
     }
 }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
 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));
 }
Esempio n. 5
0
 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));
     }
 }