Пример #1
0
 public Response()
 {
     SerializeMessage    = true;
     Authors             = new Authors <Author>();
     Brands              = new Brands <Brand>();
     Books               = new Books <Book>();
     Countries           = new Countries <Country>();
     Genres              = new Genres <Genre>();
     Languages           = new Languages <Language>();
     PublishingCompanies = new PublishingCompanies <PublishingCompany>();
     Series              = new Serie <Series>();
 }
Пример #2
0
        public async Task <Response> Index(bool brands, bool books, bool authors, bool genres, bool series, int numPublishingCompanies)
        {
            Response response = new Response();
            PublishingCompanies <PublishingCompany> publishingCompanies = new PublishingCompanies <PublishingCompany>();

            try
            {
                if (numPublishingCompanies == 0)
                {
                    publishingCompanies.Incorporate(
                        await Context.PublishingCompany.OrderBy(x => x.Name)
                        .Include(x => x.Avatar)
                        .ToListAsync()
                        );
                }
                else
                {
                    publishingCompanies.Incorporate(
                        await Context.PublishingCompany.OrderBy(x => x.Name)
                        .Take(numPublishingCompanies)
                        .Include(x => x.Avatar)
                        .ToListAsync()
                        );
                }


                if (series)
                {
                    publishingCompanies.Union(
                        await Context.PublishingCompany.Include(x => x.PublishingCompaniesSeries)
                        .ThenInclude(y => y.Series)
                        .ToListAsync()
                        );

                    publishingCompanies.Series();
                }

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

                    publishingCompanies.Authors();
                }

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

                    publishingCompanies.Genres();
                }

                if (brands)
                {
                    publishingCompanies.Union(
                        await Context.PublishingCompany.Include(x => x.Brands)
                        .ToListAsync()
                        );
                }

                if (books)
                {
                    publishingCompanies.Union(
                        await Context.PublishingCompany.Include(x => x.Books)
                        .ThenInclude(y => y.Cover)
                        .ToListAsync()
                        );
                }

                response.PublishingCompanies = publishingCompanies;
            }
            catch (Exception ex)
            {
                response.Message    = ex.Message;
                response.BadRequest = true;
            }

            return(response);
        }