public ActionResult PersonalisedNews(string root, int limit, string filters) { // Ajax request for personalised news items (based on tags in users cookies) Item newsRoot = ItemExtensions.GetItem(root); if (limit != 4 && limit != 6) { limit = 6; } var tagIds = new string[0]; if (!string.IsNullOrWhiteSpace(filters)) { tagIds = filters.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim().ToLower()).ToArray(); } var searchResults = _newsRepository.GetNews(newsRoot, tagIds, 0, limit).Select(x => _newsRepository.CreateNewsItem(x)); var title = DictionaryPhraseRepository.Current.Get(DictionaryPaths.PersonalisedNewsTitle, "Personalised News"); return(new JsonResult { Data = GetJsonObject(searchResults, title, limit, null, null), JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
//Method to get Popular / Personalised news articles public IEnumerable <Item> GetPopularNews(Item newsRoot, int timeFrameInDays, int limit) { var result = new List <Item>(); var urlOptions = new UrlOptions() { LanguageEmbedding = LanguageEmbedding.Never, AlwaysIncludeServerUrl = false }; var newsArticlesRoot = string.Format("'%{0}%'", newsRoot.Url(urlOptions)); var popularNewsPageReport = GetPopularNewsReportingData(newsArticlesRoot, timeFrameInDays); if (popularNewsPageReport != null) { //These statements filter out the result by excluding context Item, and if context Item if of type NewsItem template, and take only number of records as per limit value. var excludedItemId = Sitecore.Context.Item?.ID; result = popularNewsPageReport.Rows.Cast <DataRow>().Select(row => row.Field <Guid>("itemid").ToString()).Distinct().Select(itemid => ItemExtensions.GetItem(itemid)).Where(x => x != null && x.ID != excludedItemId && x.IsDerived(Templates.NewsItem.ID)).Take(limit).ToList(); } return(result); }