public virtual void CanGetSearchTotal()
        {
            var searchRequest = new HostSearchRequest();

            searchRequest.HostQuery = "test";

            int results = _HostRepository.GetSearchTotal(searchRequest);

            Assert.That(results >= 1);
        }
Beispiel #2
0
        public SearchResultFormViewModel <HostDto, HostSearchRequest> Search(HostSearchRequest searchRequest)
        {
            //make sure at least one field set
            //Check.Require(searchRequest != null, "At least one field is required");

            //if (String.IsNullOrEmpty(searchRequest.HostQuery))
            //{
            //    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 <HostDto> searchResultItems = _HostRepository.Search(searchRequest, offset, entriesPerPage);

            var searchResultFormViewModel = CreateFormViewModel(searchRequest);

            searchResultFormViewModel.PageResultItems = searchResultItems;

            int resultCount = _HostRepository.GetSearchTotal(searchRequest);

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

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

            return(searchResultFormViewModel);
        }