コード例 #1
0
ファイル: BooksController.cs プロジェクト: dejvids/E-Library
        public async Task <IActionResult> GetAll(int page)
        {
            var user = await _userService.GetTestUserAsync();

            var options = new BookPagingOption {
                Items = 10, Page = page
            };
            var books = await _bookService.GetAllBooksAsync(user, options);

            return(Ok(books));
        }
コード例 #2
0
ファイル: LibraryService.cs プロジェクト: dejvids/E-Library
 public async Task <IEnumerable <BookDto> > GetAllBooksAsync(User user, BookPagingOption options)
 {
     return(await _dbContext.Books
            .Skip(options.Page *options.Items)
            .Take(options.Items)
            .Select(b =>
                    new BookDto
     {
         BookId = b.Id,
         Title = b.Title,
         Author = $"{b.Author.Surname}  {b.Author.Name}",
         TotalCount = b.TotalCount,
         FreeCount = _dbContext.BookCopies.Where(bc => bc.BorrowedBy == null && bc.Book.Id == b.Id).Count()
     })
            .ToListAsync());
 }