public ActionResult Create( Person person,HttpPostedFileBase file) { if (ModelState.IsValid) { string filename = ""; byte[] bytes; int bytesToRead; int numBytesRead; if (file != null) { filename = Path.GetFileName(file.FileName); bytes = new byte[file.ContentLength]; bytesToRead = (int) file.ContentLength; numBytesRead = 0; while (bytesToRead > 0) { int n = file.InputStream.Read(bytes,numBytesRead,bytesToRead); if (n == 0) { break; } numBytesRead += n; bytesToRead -= n; } person.Image = bytes; } db.People.Add(person); db.SaveChanges(); return RedirectToAction("Index"); } return View("Create",person); }
public ActionResult Edit(Person person) { if (ModelState.IsValid) { db.Entry(person).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(person); }