public AuthorBookLink Add(AuthorBookLink link) { db.AuthorBookLinks.Add(link); db.SaveChanges(); return(link); }
public ObjectResult Remove( [FromQuery] long authorId, [FromQuery] long bookId ) { try { AuthorBookLink link = linkRepository.Get(bookId, authorId); linkRepository.Remove(link); } catch (InvalidOperationException e) { if (e.Message == "Sequence contains no elements") { return(NotFound("No such links found")); } } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok($"link book {bookId} to author {authorId} removed")); }
public ObjectResult Add( [FromQuery] long authorId, [FromQuery] long bookId ) { try { AuthorBookLink link = new AuthorBookLink { AuthorId = authorId, BookId = bookId }; linkRepository.Add(link); } catch (DbUpdateException e) { return(BadRequest("Link already exists")); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok($"link book {bookId} to author {authorId} added")); }
public ActionResult Create(Book book) { if (ModelState.IsValid) { book.IsFavourite = false; bookService.AddBook(book); //Adding AuthorToBook var authorBookLink = new AuthorBookLink(); authorBookLink.AuthorId = book.AuthorId; authorBookLink.BookId = book.Id; authorBookLinksService.AddAuthorBookLink(authorBookLink); //Adding GenreToBook var genreBookLink = new GenreBookLink(); genreBookLink.BookId = book.Id; genreBookLink.GenreId = book.GenreId; genreBookLinksService.AddGenreBookLink(genreBookLink); //Adding GenreToAuthor var genreAuthorLink = new GenreAuthorLink(); genreAuthorLink.AuthorId = book.AuthorId; genreAuthorLink.GenreId = book.GenreId; genreAuthorLinksService.AddGenreAuthorLink(genreAuthorLink); return(RedirectToAction("Index")); } else { ViewBag.Genres = genreService.GetAllGenres(); ViewBag.Authors = authorService.GetAllAuthors(); return(View(book)); } }
public void Remove(AuthorBookLink link) { db.AuthorBookLinks.Remove(link); db.SaveChanges(); }
public void AddAuthorBookLink(AuthorBookLink authorBookLink) { db.AuthorBookLink.Add(authorBookLink); Save(); }
public void AddAuthorBookLink(AuthorBookLink authorBookLink) { authorBookLinkRepo.AddAuthorBookLink(authorBookLink); }