public async Task <List <BookFull> > GetAllBooksFull(int idAuthor) { List <Book> books = await context.Book.ToListAsync(); if (idAuthor == 0) { books = await context.Book.ToListAsync(); } else { books = context.Book.Where(b => b.IdAuthor == idAuthor).ToList(); } List <BookFull> booksFull = new List <BookFull>(); foreach (Book book in books) { BookFull bookFull = new BookFull(); bookFull.IdBook = book.Id; bookFull.ISBN = book.ISBN; bookFull.Title = book.Title; bookFull.Publisher = book.Publisher; bookFull.IdAuthor = book.IdAuthor; List <Author> autor = await GetAuthor(book.IdAuthor); bookFull.Author = autor[0].Name + " " + autor[0].LastName; List <Category> category = await GetCategory(book.IdCategory); bookFull.Category = category[0].Name; List <Country> country = await GetCountry(autor[0].IdCountry); bookFull.Country = country[0].Code; booksFull.Add(bookFull); } return(booksFull); }
public async Task<List<BookFull>> GetAllBooksFull(int idAuthor) { List<Book> books=await context.Book.ToListAsync(); if (idAuthor == 0) books = await context.Book.ToListAsync(); else books = context.Book.Where(b => b.IdAuthor == idAuthor).ToList(); List<BookFull> booksFull = new List<BookFull>(); foreach (Book book in books) { BookFull bookFull = new BookFull(); bookFull.IdBook = book.Id; bookFull.ISBN = book.ISBN; bookFull.Title = book.Title; bookFull.Publisher = book.Publisher; bookFull.IdAuthor = book.IdAuthor; List<Author> autor = await GetAuthor(book.IdAuthor); bookFull.Author = autor[0].Name + " " + autor[0].LastName; List<Category> category = await GetCategory(book.IdCategory); bookFull.Category = category[0].Name; List<Country> country = await GetCountry(autor[0].IdCountry); bookFull.Country = country[0].Code; booksFull.Add(bookFull); } return booksFull; }