Beispiel #1
0
        public virtual void CanSearch()
        {
            var searchRequest = new AgencySearchRequest();

            searchRequest.AgencyQuery = "e";

            IList <AgencyDto> results = _agencyRepository.Search(searchRequest, 0, 20);

            Assert.That(results.Count > 1 && results.Count <= 20);
        }
        public SearchResultFormViewModel <AgencyDto, AgencySearchRequest> Search(AgencySearchRequest searchRequest)
        {
            //make sure at least one field set
            //Check.Require(searchRequest != null, "At least one field is required");

            //if (String.IsNullOrEmpty(searchRequest.AgencyQuery))
            //{
            //    Check.Require(1 == 0, "At least one field is required");
            //}

            if (searchRequest.CurrentPageNumber == 0)
            {
                searchRequest.CurrentPageNumber = 1;
            }
            if (string.IsNullOrEmpty(searchRequest.SortColumn))
            {
                searchRequest.SortColumn = DEFAULT_SORT_COLUMN;
                searchRequest.SortOrder  = DEFAULT_SORT_ORDER;
            }
            const int entriesPerPage = 20;
            int       offset         = entriesPerPage * (searchRequest.CurrentPageNumber - 1);

            IList <AgencyDto> searchResultItems = _agencyRepository.Search(searchRequest, offset, entriesPerPage);

            var searchResultFormViewModel = CreateFormViewModel(searchRequest);

            searchResultFormViewModel.PageResultItems = searchResultItems;

            int resultCount = _agencyRepository.GetSearchTotal(searchRequest);

            searchResultFormViewModel.TotalResultCount  = resultCount;
            searchResultFormViewModel.CurrentPageNumber = searchRequest.CurrentPageNumber;

            searchResultFormViewModel.TotalPageCount = resultCount / entriesPerPage;
            if (resultCount % entriesPerPage > 0)
            {
                searchResultFormViewModel.TotalPageCount++;
            }

            return(searchResultFormViewModel);
        }