Example #1
0
        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();
        }
Example #2
0
 public ActionResult Edit(Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(book);
 }