public ActionResult Edit([Bind(Include = "ID,Name,Author,Introduce,imagePath,pubYear,CategoriesID")] Book book, HttpPostedFileBase image_book)
{
if (ModelState.IsValid)
{
if (image_book != null && image_book.ContentLength > 0)
{
string pic = System.IO.Path.GetFileName(image_book.FileName);
string path = System.IO.Path.Combine(Server.MapPath("~/Content/imageBook"), pic);
if (System.IO.File.Exists(path))
{
int count = 2;
while (System.IO.File.Exists(path))
{
pic = count.ToString() + pic;
path = System.IO.Path.Combine(Server.MapPath("~/Content/imageBook"), pic);
}
}
image_book.SaveAs(path);
book.imagePath = pic;
}
db.Entry(book).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
//ViewBag.CategoriesID = new SelectList(db.Categories, "ID", "Name", book.CategoriesID);
return View(book);
}