public ActionResult AddBook(TBLBook p) { var book = db.TBLCategory.Where(k => k.CategoryID == p.TBLCategory.CategoryID).FirstOrDefault(); var aut = db.TblAuthor.Where(a => a.authorID == p.TblAuthor.authorID).FirstOrDefault(); var loc = db.Libraries.Where(a => a.LibrariesID == p.Libraries.LibrariesID).FirstOrDefault(); p.TBLCategory = book; p.TblAuthor = aut; p.Libraries = loc; db.TBLBook.Add(p); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult SaveBook(TBLBook p) { var book = db.TBLBook.Find(p.bookID); book.bookName = p.bookName; book.bookYear = p.bookYear; book.bookPublisher = p.bookPublisher; book.bookPage = p.bookPage; book.bookCase = p.bookCase; var bk = db.TBLCategory.Where(b => b.CategoryID == p.TBLCategory.CategoryID).FirstOrDefault(); var aut = db.TblAuthor.Where(b => b.authorID == p.TblAuthor.authorID).FirstOrDefault(); var loc = db.Libraries.Where(b => b.LibrariesID == p.Libraries.LibrariesID).FirstOrDefault(); book.bookCategory = bk.CategoryID; book.bookAuthor = aut.authorID; book.LibraryID = loc.LibrariesID; db.SaveChanges(); return(RedirectToAction("Index")); }