//Render page Create new book public ActionResult Create() { //get list categories existing and assign for viewbag SelectList categories = new SelectList(CategoryDao.GetAllCategory(), "categoryID", "categoryName"); ViewBag.Categories = categories; //get list authors existing and assign for viewbag SelectList authors = new SelectList(AuthorDao.GetListAuthors(), "authorID", "authorName"); ViewBag.Authors = authors; //get list publishers existing and assign for viewbag SelectList publishers = new SelectList(PublisherDao.GetListPublisher(), "publisherID", "publisherName"); ViewBag.Publishers = publishers; return(PartialView("_CreateBook", new Book())); }
//Render page edit book by book id public ActionResult Edit(int id) { //get book need to edit var book = BookDao.GetBook(id); //store older picture if user don't choose new picture oldPicture = book.Picture; //get list categories existing and assign for viewbag SelectList categories = new SelectList(CategoryDao.GetAllCategory(), "categoryID", "categoryName", book.Category.CategoryName); ViewBag.Categories = categories; //get list authors existing and assign for viewbag SelectList authors = new SelectList(AuthorDao.GetListAuthors(), "authorID", "authorName", book.Author.AuthorName); ViewBag.Authors = authors; //get list publishers existing and assign for viewbag SelectList publishers = new SelectList(PublisherDao.GetListPublisher(), "publisherID", "publisherName", book.Publisher.PublisherName); ViewBag.Publishers = publishers; return(View("_EditBook", book)); }