public ActionResult Create(tbl_books collection) { try { // TODO: Add insert logic here var li = context.tbl_user.ToList(); ViewBag.UsersList = new SelectList(li, "user_id", "user_name"); tbl_books book = new tbl_books { book_author = collection.book_author, book_edition = collection.book_edition, book_name = collection.book_name, user_id = collection.user_id, book_price = collection.book_price, book_qunatity = collection.book_qunatity }; context.tbl_books.Add(book); context.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { return(View()); } }
public ActionResult Edit(int id, tbl_books bookModel) { try { // TODO: Add update logic here var book = context.tbl_books.Where(b => b.book_id == id).FirstOrDefault(); book.book_author = bookModel.book_author; book.book_edition = bookModel.book_edition; book.book_name = bookModel.book_name; book.book_price = bookModel.book_price; book.book_qunatity = bookModel.book_qunatity; book.user_id = bookModel.user_id; context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }