Ejemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "ID,Name,Description,Components,CategoryID,ProfileID,TypeID")] Recipe recipe)
        {
            HttpPostedFileBase file = Request.Files["fileWithPicture"];

            if (file != null && file.ContentLength > 0)
            {
                recipe.Picture = System.Guid.NewGuid().ToString();
                recipe.Picture = file.FileName;
                file.SaveAs(HttpContext.Server.MapPath("~/Pictures/") + recipe.Picture);
            }

            if (ModelState.IsValid)
            {
                db.Entry(recipe).State = EntityState.Modified;

                if (file == null || file.ContentLength == 0)
                {
                    db.Entry(recipe).Property(p => p.Picture).IsModified = false;
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Name", recipe.CategoryID);
            ViewBag.ProfileID  = new SelectList(db.Profiles, "ID", "Login", recipe.ProfileID);
            ViewBag.TypeID     = new SelectList(db.Types, "ID", "Name", recipe.TypeID);
            return(View(recipe));
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "ID,Login,FirstName,LastName,Age,IsMale")] Profile profile)
 {
     if (ModelState.IsValid)
     {
         db.Entry(profile).State = EntityState.Modified;
         db.SaveChanges();
     }
     return(View(profile));
 }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "ID,Name")] Models.Type type)
 {
     if (ModelState.IsValid)
     {
         db.Entry(type).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(type));
 }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "ID,Rate,RecipeID,ProfileID")] Rating rating)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rating).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProfileID = new SelectList(db.Profiles, "ID", "Login", rating.ProfileID);
     ViewBag.RecipeID  = new SelectList(db.Recipes, "ID", "Name", rating.RecipeID);
     return(View(rating));
 }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "ID,Content,CommentDate,RecipeID,ProfileID")] Comment comment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(comment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProfileID = new SelectList(db.Profiles, "ID", "Login", comment.ProfileID);
     ViewBag.RecipeID  = new SelectList(db.Recipes, "ID", "Name", comment.RecipeID);
     return(View(comment));
 }