示例#1
0
 public ActionResult Index(bool partial = false)
 {
     int user = 0;
     string name = "Guest";
     ViewBag.isManager = 0;
     if (Session["user"] is user)
     {
         user = (Session["user"] as user).id;
         name = (Session["user"] as user).name;
         ViewBag.isManager = Convert.ToInt32((Session["user"] as user).user_or_manager);
     }
     if (Session["user"] == null)
         user = -1;
     ViewBag.id = user;
     ViewBag.name = name;
     recipe r = new recipe();
     if (partial)
     {
         return PartialView();
     }
     else
     {
         return View();
     }
 }
示例#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
 // return recipe for serialize
 public recipe getSerialize()
 {
     recipe r = new recipe() {
         id = this.id,
         name = this.name,
         portions = this.portions,
         tips = this.tips,
         approved = this.approved,
         instructions = this.instructions,
         preparation = this.preparation,
         description = this.description,
         category1 = re.categories.FirstOrDefault(c=>c.id==this.category).getSerialize(),
         category = this.category
     };
     return r;
 }
示例#4
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);
     }
 }