public void AddAuthorToBook(AddAuthorToBookBindingModel bindingModel) { Book book = this.Context.Books.Find(bindingModel.Id); Author author = this.Context.Authors .First(a => a.Id.ToString() == bindingModel.SelectAuthors); book.Authors.Add(author); this.Context.SaveChanges(); }
public ActionResult AddAuthorToBook([Bind(Include = "Id,SelectAuthors")] AddAuthorToBookBindingModel bindingModel) { if (ModelState.IsValid) { this.bookService.AddAuthorToBook(bindingModel); this.TempData["Success"] = "Success"; return(RedirectToAction("Details", "Books", new { id = bindingModel.Id })); } this.TempData["Error"] = "Error"; return(RedirectToAction("Details", "Books", new { id = bindingModel.Id })); }