public IHttpActionResult AddAuthor(Author newAuthor) { if (newAuthor != null) { dbContext.Author.Add(newAuthor); dbContext.SaveChanges(); } return(Ok()); }
public IHttpActionResult AddBook([FromBody] AddBookDTO newBook) { if (newBook != null) { var authorId = getAuthorIdByLastName(newBook.AuthorLastName); Book b = new Book { Id = dbContext.Book.OrderByDescending(a => a.Id).FirstOrDefault().Id + 1, Title = newBook.Title, AuthorId = authorId, Year = newBook.Year }; dbContext.Book.Add(b); dbContext.SaveChanges(); } return(Ok()); }