Example #1
0
        public async Task <Response> Index(bool books, bool authors, bool publishingCompanies, bool series, bool brands, int numGenres)
        {
            Response       response = new Response();
            Genres <Genre> genres   = new Genres <Genre>();

            try
            {
                if (numGenres == 0)
                {
                    genres.Incorporate(
                        await Context.Genre.OrderBy(x => x.Name)
                        .Include(x => x.Avatar)
                        .ToListAsync()
                        );
                }
                else
                {
                    genres.Incorporate(
                        await Context.Genre.OrderBy(x => x.Name)
                        .Include(x => x.Avatar)
                        .Take(numGenres)
                        .ToListAsync()
                        );
                }


                if (series)
                {
                    genres.Union(
                        await Context.Genre.Include(x => x.GenresSeries)
                        .ThenInclude(y => y.Series)
                        .ToListAsync()
                        );

                    genres.Series();
                }

                if (books)
                {
                    genres.Union(
                        await Context.Genre.Include(x => x.GenresBooks)
                        .ThenInclude(y => y.Book)
                        .ThenInclude(y => y.Cover)
                        .ToListAsync()
                        );

                    genres.Books();
                }

                if (authors)
                {
                    genres.Union(
                        await Context.Genre.Include(x => x.GenresAuthors)
                        .ThenInclude(y => y.Genre)
                        .ToListAsync()
                        );

                    genres.Authors();
                }

                if (publishingCompanies)
                {
                    genres.Union(
                        await Context.Genre.Include(x => x.GenresPublishingCompanies)
                        .ThenInclude(y => y.PublishingCompany)
                        .ToListAsync()
                        );

                    genres.PublishingCompanies();
                }

                if (brands)
                {
                    genres.Union(
                        await Context.Genre.Include(x => x.GenresBrands)
                        .ThenInclude(y => y.Brand)
                        .ToListAsync()
                        );

                    genres.Brands();
                }

                response.Genres = genres;
            }
            catch (Exception ex)
            {
                response.Message    = ex.Message;
                response.BadRequest = true;
            }

            return(response);
        }