public SearchResultFormViewModel<PersonDto, PersonSearchRequest> CreateFormViewModel(
            PersonSearchRequest searchRequest)
        {
            var viewModel = new SearchResultFormViewModel<PersonDto, PersonSearchRequest> { SearchRequest = searchRequest };
            searchRequest.Supervisors = _personRepository.GetActiveSupervisors(-1, "LastName", "Asc");

            return viewModel;
        }
 public SearchResultFormViewModel<PersonDto, PersonSearchRequest> CreateFormViewModel()
 {
     var searchRequest = new PersonSearchRequest
                             {
                                 Supervisors = _personRepository.GetActiveSupervisors(-1, "LastName", "Asc")
                             };
     SearchResultFormViewModel<PersonDto, PersonSearchRequest> viewModel = Search(searchRequest);
     viewModel.SearchRequest = searchRequest;
     return viewModel;
 }
        public SearchResultFormViewModel<PersonDto, PersonSearchRequest> Search(PersonSearchRequest searchRequest)
        {
            //make sure at least one field set
            //Check.Require(searchRequest != null, "At least one field is required");

            //if (searchRequest.SupervisorId == null && String.IsNullOrEmpty(searchRequest.NameQuery && searchRequest.SId == null))
            //{
            //    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<PersonDto> searchResultItems = _personRepository.Search(searchRequest, offset, entriesPerPage);

            SearchResultFormViewModel<PersonDto, PersonSearchRequest> searchResultFormViewModel =
                CreateFormViewModel(searchRequest);

            searchResultFormViewModel.PageResultItems = searchResultItems;

            int resultCount = _personRepository.GetSearchTotal(searchRequest);
            searchResultFormViewModel.TotalResultCount = resultCount;

            searchResultFormViewModel.CurrentPageNumber = searchRequest.CurrentPageNumber;

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

            return searchResultFormViewModel;
        }
        private SearchResultFormViewModel<PersonDto, PersonSearchRequest> LoadSearchResults(
            PersonSearchRequest searchRequest)
        {
            const int entriesPerPage = 20;
            int offset = entriesPerPage * (searchRequest.CurrentPageNumber - 1);

            IList<PersonDto> searchResultItems = _personRepository.Search(searchRequest, offset, entriesPerPage);

            SearchResultFormViewModel<PersonDto, PersonSearchRequest> searchResultFormViewModel =
                CreateFormViewModel(searchRequest);
            //searchResultFormViewModel.SearchRequest = searchRequest;

            searchResultFormViewModel.PageResultItems = searchResultItems;

            int resultCount = _personRepository.GetSearchTotal(searchRequest);
            searchResultFormViewModel.TotalResultCount = resultCount;

            searchResultFormViewModel.CurrentPageNumber = searchRequest.CurrentPageNumber;

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

            return searchResultFormViewModel;
        }
Exemplo n.º 5
0
 public ActionResult Search(PersonSearchRequest searchRequest)
 {
     SearchResultFormViewModel<PersonDto, PersonSearchRequest> formViewModel = null;
     try
     {
         formViewModel = _personSearchManagementService.Search(searchRequest);
         Session.Add(SEARCH_PARAMETERS, searchRequest);
     }
     catch (PreconditionException pde)
     {
         TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = pde.Message;
         formViewModel = _personSearchManagementService.CreateFormViewModel(searchRequest);
     }
     return View("Index", formViewModel);
 }
Exemplo n.º 6
0
        public virtual void CanSearch()
        {
            var searchRequest = new PersonSearchRequest();
            searchRequest.NameQuery = "e";

            IList<PersonDto> results = _personRepository.Search(searchRequest, 0, 20);
            Assert.That(results.Count > 1 && results.Count <= 20);
        }
Exemplo n.º 7
0
        public virtual void CanGetSearchTotal()
        {
            var searchRequest = new PersonSearchRequest();
            searchRequest.NameQuery = "zamor";

            int results = _personRepository.GetSearchTotal(searchRequest);
            Assert.That(results == 1);
        }