public async Task <SearchResultsVm <BlogPostSrVm[]> > SearchBlogPostsAsync(BlogPostSc sc)
        {
            //Visitors can only view published blog posts
            if (_usersService.GetUser() == null)
            {
                sc.Status = EnBlogPostStatus.Published;
            }

            var specification = new BlogPostSpecification();

            specification.SetCriteria(sc);

            var itemsOnPage = await _blogPostsRepository.SearchAsync(specification);

            var totalItems = await _blogPostsRepository.CountAsync(specification);

            var results = new SearchResultsVm <BlogPostSrVm[]>(
                _mapper.Map <BlogPostSrVm[]>(itemsOnPage),
                totalItems,
                itemsOnPage.Count,
                sc.CurrentPage,
                sc.Take);

            return(results);
        }
Beispiel #2
0
        public ActionResult Index(SearchResultsVm searchResultsVm)
        {
            var parameters = Mapper.Map <SearchParametersVm, SearchParameters>(searchResultsVm.Parameters);

            parameters.PageSize = _pageSize;

            var foundGames  = _gameLogic.Search(parameters);
            var mappedGames = Mapper.Map <IEnumerable <GameEntity>, IEnumerable <GamePreviewVm> >(foundGames.Data);

            var totalPages = (int)Math.Ceiling((double)foundGames.Count / _pageSize);

            if (searchResultsVm.Items == null)
            {
                searchResultsVm.Items = new PagedItems <GamePreviewVm>()
                {
                    PageInfo = new PageInfo
                    {
                        PageLinksCount = (totalPages < _maxPageSelectors) ? totalPages : _maxPageSelectors,
                        TotalPages     = totalPages
                    }
                };
            }

            searchResultsVm.Items.Data = mappedGames;
            searchResultsVm.Items.PageInfo.CurrentPage = searchResultsVm.Parameters.PageNumber;
            searchResultsVm.Items.PageInfo.StartIndex  = GetStartIndex(searchResultsVm.Parameters.PageNumber, totalPages);

            return(View(searchResultsVm));
        }
        public async Task <Results <SearchResultsVm> > SearchAsync(int projectId, SearchData searchData)
        {
            int offset = Math.Max(searchData.PageNumber, 0) * searchData.ItemsPerPage;

            IReadOnlyList <Document> documents;
            int totalCount;

            try
            {
                var hiddenResults = await GetHiddenResultsAsync(projectId);

                var allResultIds = (await _searchResultsCacheManager.GetSearchResultsAsync(projectId, searchData)).Except(hiddenResults).ToList();

                documents = await _getDocumentProcessor.GetDocumentsAsync(allResultIds.Skip(offset).Take(searchData.ItemsPerPage));

                totalCount = allResultIds.Count;
            }
            catch (Exception e)
            {
                return(new Results <SearchResultsVm> {
                    Exceptions = { e }
                });
            }

            var vm = new SearchResultsVm
            {
                Results = documents.Select(d => new ResultVm
                {
                    Id          = d.Id,
                    Title       = d.Title,
                    PublishDate = d.PublishDate,
                    Conference  = d.PublicationTitle,
                    Abstract    = d.Abstract,
                    AuthorName  = string.Join(", ", d.Authors.Select(a => a.Name)),
                    CiteCount   = d.CiteCount
                })
                          .ToList(),
                NumberOfPages = (int)Math.Ceiling((double)totalCount / searchData.ItemsPerPage)
            };

            return(new Results <SearchResultsVm>
            {
                Data = vm
            });
        }