public Book AddAuthorToBook(BookDto bookDto) { Book book = new Book() { Id = bookDto.Id, Name = bookDto.Name, PageCount = bookDto.PageCount, Language = bookDto.Language, ISBN = bookDto.ISBN }; if (bookDto.AuthorId != null) { book.Author = context.Authors.FirstOrDefault(x => x.Id == bookDto.AuthorId); } context.Add(book); context.SaveChanges(); return(book); }
public TEntity Add(TEntity entity) { context.Set <TEntity>().Add(entity); context.SaveChanges(); return(entity); }