public ActionResult InsertBook(Book book, HttpPostedFileBase PhotoPath)
{
if (ModelState.IsValid)
{
int MaxID = 1;
if (db.Books.Count() > 0)
{ MaxID = (from a in db.Books select a.BookID).Max(); }
var exten = Path.GetExtension(PhotoPath.FileName);
var Name = String.Join(null, MaxID.ToString(), exten);
book.PhotoPath = Name;
book.CountVistor = 0;
var path = Path.Combine(Server.MapPath("~/Photos/"), Name);
PhotoPath.SaveAs(path);
db.Books.Add(book);
db.SaveChanges();
return RedirectToAction("Index");
}
return View();
}