예제 #1
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() }));
     }
 }
예제 #2
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() }));
     }
 }
예제 #3
0
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
 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));
     }
 }
예제 #6
0
 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));
     }
 }
예제 #7
0
 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));
     }
 }
예제 #8
0
 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));
     }
 }
예제 #9
0
 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));
     }
 }
예제 #10
0
 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));
     }
 }
예제 #11
0
 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));
     }
 }
예제 #12
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));
     }
 }