private BookModels GetBook(int bookId) { var model = new BookModels(); using (var repo = new BookRepository()) { model = repo.Details(bookId); } using (var repo_a = new AuthorRepository()) { model.AuthorList = repo_a.FindAuthorsByBook(bookId).ToList(); } foreach (var i in model.AuthorList) { model.SelectedAuthors.Add(i.Id); } return(model); }
// // GET: /BookModels/ public ActionResult Index() { IEnumerable <BookModels> books; using (var repo = new BookRepository()) { books = repo.FindBooks(); } foreach (var book in books) { using (var repo_a = new AuthorRepository()) { //ViewBag.AuthorList = repo.GetAll().ToList(); book.AuthorList = repo_a.FindAuthorsByBook(book.Id).ToList(); } } return(View("Index", books)); }