示例#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() });
     }
 }
示例#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() });
     }
 }
示例#3
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);
     }
 }