// GET: BookController/Create public ActionResult Create() { var dto = new AuthorForBookDTO { authors = _authorRepo.list().ToList() }; return(View(dto)); }
// GET: BookController/Edit/5 public ActionResult Edit(int id) { var book = _bookrepo.Find(id); var idAuthor = book.author == null ? 0 : book.author.Id; var Dto = new AuthorForBookDTO() { Id = book.Id, title = book.title, Discrption = book.Discrption, AuthorId = book.author.Id, authors = _authorRepo.list().ToList(), }; return(View()); }
public ActionResult Create(AuthorForBookDTO book) { try { var Author = _authorRepo.Find(book.AuthorId); var bookDTO = new Book() { Id = book.Id, title = book.title, Discrption = book.Discrption, author = Author }; _bookrepo.Add(bookDTO); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }