コード例 #1
0
        public async Task <Response> Index(bool series, bool books, bool genres, bool publishingCompanies, bool country, bool brands, int numAuthors)
        {
            Response         response = new Response();
            Authors <Author> authors  = new Authors <Author>();

            try
            {
                if (numAuthors == 0)
                {
                    authors.Incorporate(
                        await Context.Author.OrderBy(x => x.Name)
                        .Include(x => x.Avatar)
                        .ToListAsync()
                        );
                }
                else
                {
                    authors.Incorporate(
                        await Context.Author.OrderBy(x => x.Name)
                        .Include(x => x.Avatar)
                        .Take(numAuthors)
                        .ToListAsync()
                        );
                }


                if (series)
                {
                    authors.Union(
                        await Context.Author.Include(x => x.AuthorsSeries)
                        .ThenInclude(y => y.Series)
                        .ToListAsync()
                        );

                    authors.Series();
                }

                if (books)
                {
                    authors.Union(
                        await Context.Author.Include(x => x.AuthorsBooks)
                        .ThenInclude(y => y.Book)
                        .ThenInclude(y => y.Cover)
                        .ToListAsync()
                        );

                    authors.Books();
                }

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

                    authors.Genres();
                }

                if (publishingCompanies)
                {
                    authors.Union(
                        await Context.Author.Include(x => x.PublishingCompaniesAuthors)
                        .ThenInclude(y => y.PublishingCompany)
                        .ToListAsync()
                        );

                    authors.PublishingCompanies();
                }

                if (brands)
                {
                    authors.Union(
                        await Context.Author.Include(x => x.BrandsAuthors)
                        .ThenInclude(y => y.Brand)
                        .ToListAsync()
                        );

                    authors.Brands();
                }

                if (country)
                {
                    authors.Union(
                        await Context.Author.Include(x => x.Country)
                        .ToListAsync()
                        );
                }

                response.Authors = authors;
            }
            catch (Exception ex)
            {
                response.Message    = ex.Message;
                response.BadRequest = true;
            }

            return(response);
        }