public ActionResult Edit(Book book, HttpPostedFileBase PathImage)
{
if (ModelState.IsValid)
{
if ((PathImage != null && PathImage.ContentLength > 0))
{
var fileName = Path.GetFileName(PathImage.FileName);
var imageName = "book" + db.Books.Select(b => b.Id).Max() + ".jpg";
var path = Path.Combine(Server.MapPath("~/Images"), imageName);
PathImage.SaveAs(path);
book.PathImage = "/Images/" + imageName;
}
db.Entry(book).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.Categories = db.Categories.ToList();
return View(book);
}