Ejemplo n.º 1
0
            protected async Task <int> GetTotalPages(
                BooksQuery request,
                bool onlyAvailable = true,
                int?authorId       = default,
                CancellationToken cancellationToken = default)
            {
                var bookSpecification = this.GetBookSpecification(request, onlyAvailable);

                var authorSpecification = this.GetAuthorSpecification(request, authorId);

                var totalBooks = await this.bookRepository.Total(
                    bookSpecification,
                    authorSpecification,
                    cancellationToken);

                return((int)Math.Ceiling((double)totalBooks / BooksPerPage));
            }
Ejemplo n.º 2
0
            protected async Task <IEnumerable <TOutputModel> > GetBookListings <TOutputModel>(
                BooksQuery request,
                bool onlyAvailable = true,
                int?authorId       = default,
                CancellationToken cancellationToken = default)
            {
                var bookSpecification = this.GetBookSpecification(request, onlyAvailable);

                var authorSpecification = this.GetAuthorSpecification(request, authorId);

                var searchOrder = new BooksSortOrder(request.SortBy, request.Order);

                var skip = (request.Page - 1) * BooksPerPage;

                return(await this.bookRepository.GetBookListings <TOutputModel>(
                           bookSpecification,
                           authorSpecification,
                           searchOrder,
                           skip,
                           take : BooksPerPage,
                           cancellationToken));
            }
Ejemplo n.º 3
0
 private Specification <Book> GetBookSpecification(BooksQuery request, bool onlyAvailable)
 => new BookByPublisherSpecification(request.Publisher)
 .And(new BookByPriceSpecification(request.MinPrice, request.MaxPrice))
 .And(new BookOnlyAvailableSpecification(onlyAvailable));
Ejemplo n.º 4
0
 private Specification <Author> GetAuthorSpecification(BooksQuery request, int?authorId)
 => new AuthorByIdSpecification(authorId)
 .And(new AuthorByNameSpecification(request.Author));