public ActionResult SiteSearch(string q = null, int p = 1, int s = 10) { var searchOptions = new SiteSearchOptions(q, PageContext.Current.Item, ContentSearchPagingOptions.FromPage(p, s)); var model = new SiteSearchViewModel { Options = searchOptions }; if (!string.IsNullOrWhiteSpace(q)) { var results = _siteSearcher.Search(searchOptions); model.TotalResults = results.TotalSearchResults; model.Results = results.Documents.Select(x => new SiteSearchResultViewModel { Name = x.Name, Updated = x.Updated, Url = x.Url }); } return(View(model)); }
public async Task <IList <Site> > GetFilteredSites(SiteSearchViewModel SearchModel) { var sites = from s in context.Sites select s; if (SearchModel.CustomerID.HasValue) { sites = sites.Where(x => x.CustomerID == SearchModel.CustomerID); } if (SearchModel.SiteNumber != null) { sites = sites.Where(x => x.SiteNumber.Contains(SearchModel.SiteNumber)); } if (SearchModel.CountryID.HasValue) { sites = sites.Where(x => x.CountryID == SearchModel.CountryID); } if (SearchModel.StateID.HasValue) { sites = sites.Where(x => x.StateID == SearchModel.StateID); } return(await sites.ToListAsync()); }