public ActionResult UpdateFood(Food updateFood, HttpPostedFileBase uploadedFile) { string fileName = string.Empty; if (uploadedFile != null) { fileName = System.IO.Path.GetFileName(uploadedFile.FileName); updateFood.ImageFileName = fileName; string imageFilePathOnServer = System.IO.Path.Combine(Server.MapPath("~/UploadedFiles"), fileName); uploadedFile.SaveAs(imageFilePathOnServer); } this.dbContext.Foods.Attach(updateFood); this.dbContext.Entry(updateFood).State = System.Data.Entity.EntityState.Modified; this.dbContext.SaveChanges(); return RedirectToAction("ViewFood"); }
public ActionResult CreateNewFood(Food newFood) { this.dbContext.Foods.Add(newFood); this.dbContext.SaveChanges(); return RedirectToAction("ViewFood"); }