public async Task <Response> Index(bool publishingCompany, bool books, bool authors, bool genres, bool series, int numBrands) { Response response = new Response(); Brands <Brand> brands = new Brands <Brand>(); try { if (numBrands == 0) { brands.Incorporate( await Context.Brand.OrderBy(x => x.Name) .Include(x => x.Avatar) .ToListAsync() ); } else { brands.Incorporate( await Context.Brand.OrderBy(x => x.Name) .Include(x => x.Avatar) .Take(numBrands) .ToListAsync() ); } if (series) { brands.Union( await Context.Brand.Include(x => x.BrandsSeries) .ThenInclude(y => y.Series) .ToListAsync() ); brands.Series(); } if (authors) { brands.Union( await Context.Brand.Include(x => x.BrandsAuthors) .ThenInclude(y => y.Author) .ToListAsync() ); brands.Authors(); } if (genres) { brands.Union( await Context.Brand.Include(x => x.GenresBrands) .ThenInclude(y => y.Genre) .ToListAsync() ); brands.Genres(); } if (publishingCompany) { brands.Union( await Context.Brand.Include(x => x.PublishingCompany) .ToListAsync() ); } if (books) { brands.Union( await Context.Brand.Include(x => x.Books) .ThenInclude(y => y.Cover) .ToListAsync() ); } response.Brands = brands; } catch (Exception ex) { response.Message = ex.Message; response.BadRequest = true; } return(response); }