// GET: Books public ActionResult Index() { _bookEntities = new bookEntities(); List <books> books = _bookEntities.books.ToList(); return(View(books)); }
public ActionResult Update(int?id) { if (id == null) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest)); } var db = new bookEntities(); var toUpdate = db.books.Find(id); return(View(toUpdate)); }
public ActionResult Delete(int?id) { var db = new bookEntities(); var toDelete = db.books.Find(id); if (toDelete != null) { db.books.Remove(toDelete); db.SaveChanges(); } return(RedirectToAction("Show", "Admin")); }
public ActionResult Create(book model) { if (ModelState.IsValid) { var db = new bookEntities(); db.books.Add(new book { Firstname = model.Firstname, Secondname = model.Secondname, Bookname = model.Bookname, Author = model.Author, Datetaken = model.Datetaken }); db.SaveChanges(); } return(RedirectToAction("Show", "Admin")); }
public ActionResult Update(int?id, book model) { var db = new bookEntities(); var toUpdate = db.books.Find(id); if (ModelState.IsValid) { if (toUpdate != null) { toUpdate.Id = id ?? default(int); toUpdate.Firstname = model.Firstname; toUpdate.Secondname = model.Secondname; toUpdate.Bookname = model.Bookname; toUpdate.Author = model.Author; toUpdate.Datetaken = model.Datetaken; db.SaveChanges(); } } return(RedirectToAction("Show", "Admin")); }
public ActionResult Show() { var entities = new bookEntities(); return(View(entities.books.ToList())); }