public ActionResult EditBook([Bind(Include = "BookId,Title,Author,ReleaseDate,Description,Cost,ImagePath")] Book book, HttpPostedFileBase ImageBrowse)
{
if (ModelState.IsValid)
{
db.Entry(book).State = EntityState.Modified;
if (ImageBrowse != null && ImageBrowse.ContentLength > 0)
{
var pic = book.BookId + ".jpg";
var path = System.IO.Path.Combine(
Server.MapPath("~/Content/Images/Covers"), pic);
ImageBrowse.SaveAs(path);
book.ImagePath = pic;
}
db.SaveChanges();
var categories = db.Categories.ToList();
List<Genre> newCategories = new List<Genre>();
foreach (var category in categories)
{
if (Request["Category" + category.GenreId] != "false")
{
newCategories.Add(category);
}
}
UpdateBookCategory(book.BookId, newCategories);
return RedirectToAction("Books");
}
return View(book);
}