public bool CreateBook(List <int> authorId, List <int> categorieId, Book book) { var authors = _bookDBContext.Authors.Where(a => authorId.Contains(a.Id)).ToList(); var categories = _bookDBContext.Categories.Where(c => categorieId.Contains(c.Id)).ToList(); foreach (var a in authors) { var bookauthor = new BookAuthor { Author = a, Book = book }; } foreach (var c in categories) { var bookcategories = new BookCategory { Category = c, Book = book }; } _bookDBContext.Add(book); return(Save()); }
public async Task <IActionResult> Add([Bind("bookId,title,author,isbn,publisher,year")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }
public async Task <IActionResult> Create([Bind("BookId,Title,Author")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }
public async Task <IActionResult> Create([Bind("BookID,Title,PubDate,Category,AuthorID")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AuthorID"] = new SelectList(_context.Set <Author>(), "AuthorID", "LastName", book.AuthorID); return(View(book)); }