public async Task <IActionResult> GetFilterAuthors(AuthorFilterArgs filterArgs, int?catalogPage) { var authors = await _authorFilteringService.GetFilteredAuthors(_context, filterArgs, catalogPage); return(Json(new GetAuthorsViewModel() { Authors = authors, FilterArgs = filterArgs })); }
public async Task <PaginationList <Author> > GetFilteredAuthors(BookStoreContext context, AuthorFilterArgs filterArgs, int?catalogPage) { CurrentSortOrder = !string.IsNullOrEmpty(filterArgs.SortOrder) ? "desc" : "asc"; var authors = context.Author.Include(author => author.Book).Select(author => author); authors = GetFilteredAuthorsByGenre(authors, filterArgs.Genre); authors = GetFilteredAuthorsBySearchString(authors, filterArgs.SearchString, ref catalogPage); authors = SelectSortOrder(authors, filterArgs.SortOrder); return(await PaginationList <Author> .CreateAsync(authors.AsNoTracking(), catalogPage ?? 1, pageSize : 3)); }