Exemplo n.º 1
0
        public async Task <Result <PagedResult <BookListItem> > > ListAllBooksAsync(BookListCriteria criteria)
        {
            var result = new Result <PagedResult <BookListItem> >();

            var queryResult = await _listBooksQuery.Execute(criteria);

            if (queryResult.IsSuccess)
            {
                var rowItems = queryResult.Value
                               .Skip(criteria.FirstRecord)
                               .Take(criteria.PageSize)
                               .ToList();

                result.Value = new PagedResult <BookListItem>
                {
                    Items     = rowItems,
                    PageIndex = criteria.PageIndex,
                    Total     = queryResult.Value.Count
                };

                if (queryResult.Value.Count == 0)
                {
                    result.Warnings.Add(_localiser["NoBooksFound"]);
                }
            }
            else
            {
                result.Errors = queryResult.Errors;
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ListAllBooks([FromQuery] BookListCriteria criteria)
        {
            var result = await _booksService.ListAllBooksAsync(criteria);

            return(Ok(result));
        }