private void BindContent() { if (Session[Constants.SessionBehaviorSearchKey] != null) { SessionSearchResult ssr = (SessionSearchResult)Session[Constants.SessionBehaviorSearchKey]; bool hasResults = ssr.Results.Any(); hlBackToSearch.Visible = hasResults; phResultNav.Visible = ssr.Results.Count > 1; if (hasResults) { Item item = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(ssr.Challenge)); ChildChallengeItem challenge = item; litSearchChallenge.Text = String.Format("{0} {1}", DictionaryConstants.BackToFragment, challenge.ChallengeName.Text); hlBackToSearch.Visible = true; hlBackToSearch.NavigateUrl = FormHelper.GetBehaviorResultsUrl(ssr.Challenge, ssr.Grade); var currentItem = Sitecore.Context.Item; var next = ssr.GetNextResult(currentItem.ID); var prev = ssr.GetPreviousResult(currentItem.ID); PopulateLink(next, hlNext); PopulateLink(prev, hlPrev); phNavLabel.Visible = hlNext.Visible || hlPrev.Visible; } } }
public BehaviorResultSet SearchBehaviorArticles(string challenge, string grade, int page, string lang) { BehaviorResultSet results = new BehaviorResultSet(); List <BehaviorAdvice> articles; SetContextLanguage(lang); int totalResults = 0; SessionSearchResult srs = new SessionSearchResult { Challenge = challenge, Grade = grade }; // Look up challenge // Populate all results into session for article pages if ((Session != null && Session[Constants.SessionBehaviorSearchKey] != null) || page == 1) { articles = SearchHelper.GetAllBehaviorArticles(challenge, grade); srs.Results = articles; Session[Constants.SessionBehaviorSearchKey] = srs; } else { articles = ((SessionSearchResult)Session[Constants.SessionBehaviorSearchKey]).Results; } totalResults = srs.Results.Count(); int offset = (page - 1) * Constants.BEHAVIOR_SEARCH_RESULTS_ENTRIES_PER_PAGE; var pagedArticles = articles.Skip(offset).Take(Constants.BEHAVIOR_SEARCH_RESULTS_ENTRIES_PER_PAGE); var query = pagedArticles .Select(a => (BehaviorAdvicePageItem)a.GetItem()) .Where(a => a != null) .Select(a => new SearchBehaviorArticle { Title = a.TipTitle.Raw, Url = a.GetUrl(), CommentCount = Services.TelligentService.TelligentService.GetTotalComments(a.BlogId, a.BlogPostId), HelpfulCount = Services.TelligentService.TelligentService.GetTotalLikes(a.ContentId) }); results.Matches = query.ToList(); results.TotalMatches = totalResults; results.HasMoreResults = HasMoreResults(page, Constants.BEHAVIOR_SEARCH_RESULTS_ENTRIES_PER_PAGE, results.Matches.Count(), totalResults); return(results); }
private void BindControls() { if (Session[Constants.SessionBehaviorSearchKey] == null) { return; } SessionSearchResult ssr = (SessionSearchResult)Session[Constants.SessionBehaviorSearchKey]; bool hasResults = ssr.Results.Any(); if (hasResults) { List <BehaviorAdvice> results = ssr.GetResultsExcluding(new Sitecore.Data.ID(new Guid())); if (!results.Any()) { return; } var tips = results .Select(r => r.GetItem()) .Where(item => item != null) .Select(item => (BehaviorAdvicePageItem)item); if (tips.Any()) { var ids = tips.Select(i => i.ID); var currentTipIdIndexMapping = tips .Select((item, i) => new { Id = item.ID, Index = i }) .FirstOrDefault(iid => iid.Id == Sitecore.Context.Item.ID); StartSlideIndex = currentTipIdIndexMapping != null ? currentTipIdIndexMapping.Index + 1 : 0; rptTips.DataSource = tips; rptTips.DataBind(); } } }
public BehaviorResultSet SearchBehaviorArticles(string challenge, string grade, int page, string lang) { BehaviorResultSet results = new BehaviorResultSet(); List<BehaviorAdvice> articles; SetContextLanguage(lang); int totalResults = 0; SessionSearchResult srs = new SessionSearchResult { Challenge = challenge, Grade = grade }; // Look up challenge // Populate all results into session for article pages if ((Session != null && Session[Constants.SessionBehaviorSearchKey] != null) || page == 1) { articles = SearchHelper.GetAllBehaviorArticles(challenge, grade); srs.Results = articles; Session[Constants.SessionBehaviorSearchKey] = srs; } else { articles = ((SessionSearchResult)Session[Constants.SessionBehaviorSearchKey]).Results; } totalResults = srs.Results.Count(); int offset = (page - 1) * Constants.BEHAVIOR_SEARCH_RESULTS_ENTRIES_PER_PAGE; var pagedArticles = articles.Skip(offset).Take(Constants.BEHAVIOR_SEARCH_RESULTS_ENTRIES_PER_PAGE); var query = pagedArticles .Select(a => (BehaviorAdvicePageItem)a.GetItem()) .Where(a => a != null) .Select(a => new SearchBehaviorArticle { Title = a.TipTitle.Raw, Url = a.GetUrl(), CommentCount = Services.TelligentService.TelligentService.GetTotalComments(a.BlogId, a.BlogPostId), HelpfulCount = Services.TelligentService.TelligentService.GetTotalLikes(a.ContentId) }); results.Matches = query.ToList(); results.TotalMatches = totalResults; results.HasMoreResults = HasMoreResults(page, Constants.BEHAVIOR_SEARCH_RESULTS_ENTRIES_PER_PAGE, results.Matches.Count(), totalResults); return results; }