public PagedList <Author> GetAllAuthors(PagingResourceParameters paging) { var query = (IQueryable <Author>)db.Authors .Include(x => x.Books) .OrderBy(author => author.Name); if (!string.IsNullOrEmpty(paging.SearchQuery)) { query = query.Where(x => x.Name.ToLowerInvariant().Contains(paging.SearchQuery.ToLowerInvariant())); } return(PagedList <Author> .Create(query, paging.PageNumber, paging.PageSize)); }
public PagedList <Book> GetAllBooksByAuthor(int authorId, PagingResourceParameters paging) { var query = db.Books .AsNoTracking() .Where(x => x.AuthorId == authorId) .OrderBy(book => book.Title).AsQueryable(); if (!string.IsNullOrEmpty(paging.SearchQuery)) { query = query.Where(x => x.Title.ToLowerInvariant().Contains(paging.SearchQuery.ToLowerInvariant())); } return(PagedList <Book> .Create(query, paging.PageNumber, paging.PageSize)); }
public LinkedCollectionResourceWrapperDTO <AuthorDTO> GetAuthorsCollection(PagingResourceParameters paging) { var authors = authorRepository.GetAllAuthors(paging); var authorsToReturn = mapper.Map <IEnumerable <AuthorDTO> >(authors); authorsToReturn = authorsToReturn.Select(author => { author = createLinksStrategy.CreateLinksForAuthorResource(author); return(author); }); var authorsWrapper = new LinkedCollectionResourceWrapperDTO <AuthorDTO>(authorsToReturn); return(createLinksStrategy.CreateLinksForAuthors(authorsWrapper, paging, authors.HasPrevious, authors.HasNext)); }
public LinkedCollectionResourceWrapperDTO <BookDTO> GetBooks(int authorId, PagingResourceParameters paging) { var books = booksRepository.GetAllBooksByAuthor(authorId, paging); var booksToReturn = mapper.Map <IEnumerable <BookDTO> >(books); booksToReturn = booksToReturn.Select(book => { book = createLinksStrategy.CreateLinksForBookResource(book); return(book); }); var wrapper = new LinkedCollectionResourceWrapperDTO <BookDTO>(booksToReturn); return(createLinksStrategy.CreateLinksForBooks(wrapper, paging, books.HasPrevious, books.HasNext)); }
public LinkedCollectionResourceWrapperDTO <BookDTO> CreateLinksForBooks( LinkedCollectionResourceWrapperDTO <BookDTO> booksWrapper, PagingResourceParameters pagingResourceParameters, bool hasPrevious, bool hasNext) { booksWrapper.Links = new List <LinkDTO>(); booksWrapper.Links.Add(new LinkDTO( href: urlHelper.Link("GetBooks", new { }), rel: "self", method: "GET")); if (hasPrevious) { booksWrapper.Links.Add(new LinkDTO( href: urlHelper.Link("GetBooks", new { searchQuery = pagingResourceParameters.SearchQuery, pageNumber = pagingResourceParameters.PageNumber - 1, pageSize = pagingResourceParameters.PageSize }), rel: "previous", method: "GET")); } if (hasNext) { booksWrapper.Links.Add(new LinkDTO( href: urlHelper.Link("GetBooks", new { searchQuery = pagingResourceParameters.SearchQuery, pageNumber = pagingResourceParameters.PageNumber + 1, pageSize = pagingResourceParameters.PageSize }), rel: "next", method: "GET")); } return(booksWrapper); }
public IActionResult Get([FromQuery] PagingResourceParameters paging) { var authorsToReturn = getAuthorsStrategy.GetAuthorsCollection(paging); return(Ok(authorsToReturn)); }
public IActionResult Get(int authorId, [FromQuery] PagingResourceParameters paging) { var books = getBooksStrategy.GetBooks(authorId, paging); return(Ok(books)); }