public async Task <ActionResult <IEnumerable <BookDTO> > > GetBooks([FromQuery] BookSpecificationParams bookParams)
        {
            var spec = new BooksWithCategoriesAndAuthorsSpecification(bookParams);

            // get any overall count of items (after filtering has been applied)
            var countSpec  = new BooksWithFiltersForCountSpecification(bookParams);
            var totalItems = await _bookRepository.CountAsync(countSpec);

            // add pagination response headers to help client applications
            _httpContextAccessor.HttpContext.AddPaginationResponseHeaders(totalItems, bookParams.PageSize, bookParams.PageIndex);

            var books = await _bookRepository.ListAsync(spec);

            return(Ok(_mapper.Map <IEnumerable <Book>, IEnumerable <BookDTO> >(books)));
        }
예제 #2
0
        public async Task <ActionResult> GetSiteStatus()
        {
            var bookSpec  = new BooksWithFiltersForCountSpecification(new BookSpecificationParams {
            });
            var bookTotal = await _bookRepository.CountAsync(bookSpec);

            var authorSpec  = new AuthorsWithFiltersForCountSpecification(new AuthorSpecificationParams {
            });
            var authorTotal = await _authorRepository.CountAsync(authorSpec);

            var requestsOutstanding = await _requestService.GetRequestsByStatusAsync(RequestStatus.Sent);

            var requestsOverdue = await _requestService.GetRequestsOverdueAsync();

            return(Ok(new{
                BookTotal = bookTotal,
                AuthorTotal = authorTotal,
                RequestsOutstanding = requestsOutstanding.Count(),
                RequestsOverdue = requestsOverdue.Count()
            }));
        }