public ActionResult Search(string searchQuery, int page = 1, int perPage = 9) { if (_fullTextSearch == null) { _fullTextSearch = new FullTextSearchService(DocumentSession); } var books = _fullTextSearch.Search(searchQuery); ViewBag.Title = string.Format("Search Results for \"{0}\"", searchQuery); var bookInformations = new StaticPagedList <BookInformation>(books.Skip((page - 1) * perPage).Take(perPage) .Select(book => new BookInformation(book)) .ToList(), page, perPage, books.Count); if (books.Count() == 1) { return(RedirectToAction("Details", new { id = bookInformations.First().Model.Id })); } if (!bookInformations.Any()) { TempData["flashNotice"] = NoBooksFoundTxtSearch; } ViewBag.HideFilter = true; ViewBag.SearchQuery = searchQuery; return(View("List", new FilterInformation(bookInformations))); }
public ActionResult Filter(List <string> languages, List <string> ageRanges, List <string> genres, int page = 1, int perPage = 9) { languages = languages ?? new List <string>(); ageRanges = ageRanges ?? new List <string>(); genres = genres ?? new List <string>(); var books = Repository.Query <Book>(); if (ageRanges.Any()) { books = books.Where(book => book.AgeRange.In(ageRanges)); } if (languages.Any()) { books = books.Where(book => book.Language.In(languages)); } if (genres.Any()) { books = books.Where(book => book.Genre.In(genres)); } ViewBag.Title = "Books"; var bookPage = books.OrderByDescending(b => b.UpdatedAt) .Skip((page - 1) * perPage).Take(perPage) .ToList(); var bookInformations = new StaticPagedList <BookInformation>( bookPage.Select(book => new BookInformation(book)), page, perPage, books.Count()); if (!bookInformations.Any()) { TempData["flashNotice"] = NoBooksFoundTxtFilter; } return(View("List", new FilterInformation(languages, ageRanges, genres, bookInformations))); }