Ejemplo n.º 1
0
        public void SearchAsync(string query, [DefaultValue(1)] int page)
        {
            // Asynchronously query the search suggestions service
            AsyncManager.OutstandingOperations.Increment();
            searchSuggestor.BeginGetSuggestion(query, asyncResult => {
                // Now collect the final result
                string suggestion = searchSuggestor.EndGetSuggestion(asyncResult);
                AsyncManager.Parameters["searchSuggestion"] = suggestion;

                // Allow the request to complete
                AsyncManager.OutstandingOperations.Decrement();
            });

            // Run the query and construct the view model
            var results = jobAdRepository.Search(query);
            var viewModel = new SearchResultsViewModel
            {
                Query = query,
                Results = results.Skip((page - 1) * PageSize).Take(PageSize).ToList(),
                PagingInfo = new PagingInfo {
                    CurrentPage = page,
                    TotalResults = results.Count(),
                    PageSize = PageSize
                }
            };

            AsyncManager.Parameters["viewModel"] = viewModel;
        }
Ejemplo n.º 2
0
        public ActionResult SearchCompleted(SearchResultsViewModel viewModel, string searchSuggestion)
        {
            int page = viewModel.PagingInfo.CurrentPage;
            if (page < 1 || page > viewModel.PagingInfo.PageCount)
            {
                // Force the user back to a valid page index
                TempData["message"] = "Sorry - there is no page " + page + "!";
                return RedirectToAction("Search", new { viewModel.Query, page = 1 });
            }

            viewModel.SearchSuggestion = searchSuggestion;
            return View(viewModel);
        }