public async Task <Response> Index(bool series, bool authors, bool genres, bool language, bool country, bool publishingCompany, bool brand, int numBooks) { Response response = new Response(); Books <Book> books = new Books <Book>(); try { if (numBooks == 0) { books.Incorporate( await Context.Book.OrderBy(x => x.Name) .Include(x => x.Cover) .ToListAsync() ); } else { books.Incorporate( await Context.Book.OrderBy(x => x.Name) .Include(x => x.Cover) .Take(numBooks) .ToListAsync() ); } if (series) { books.Union( await Context.Book.Include(x => x.Series) .ToListAsync() ); } if (authors) { books.Union( await Context.Book.Include(x => x.AuthorsBooks) .ThenInclude(y => y.Author) .ToListAsync() ); books.Authors(); } if (genres) { books.Union( await Context.Book.Include(x => x.GenresBooks) .ThenInclude(y => y.Genre) .ToListAsync() ); books.Genres(); } if (publishingCompany) { books.Union( await Context.Book.Include(x => x.PublishingCompany) .ToListAsync() ); } if (language) { books.Union( await Context.Book.Include(x => x.Language) .ToListAsync() ); } if (brand) { books.Union( await Context.Book.Include(x => x.Brand) .ToListAsync() ); } if (country) { books.Union( await Context.Book.Include(x => x.Country) .ToListAsync() ); } response.Books = books; } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } return(response); }