protected async Task LoadFeaturedArticles() { FeaturedArticles.Clear(); try { this.IsBusy = true; var articleResults = await this.TBService.GetFeaturedArticles(); foreach (var counter in articleResults.Articles) { FeaturedArticles.Add(counter); } this.IsBusy = false; if (articleResults.Articles.Count == 0) { } //await App.Current.MainPage.DisplayAlert("Warning", "No featured articles found.", "OK"); } catch (Exception ex) { //await App.Current.MainPage.DisplayAlert("Warning", "Could not retrieve featured articles.", "OK"); } }
/// <summary> /// Fetches all the articles from datasource and performs operations to determine most recent and popular articles /// </summary> /// <returns>Returns object of type FeaturedArticles that contains Recent and Popular articles</returns> public ActionResult GetArticles() { string id = RenderingContextWrapper.GetDataSource(); Guid guid; var featuredarticles = new FeaturedArticles(); if (!string.IsNullOrEmpty(id) && Guid.TryParse(id, out guid)) { var datasourceitem = SitecoreContext.GetItem <ArticlesCollection>(guid); if (datasourceitem.ArticleList.Any()) { featuredarticles.RecentArticles = datasourceitem.ArticleList.OrderByDescending(x => x.ArticleCreatedDate).Take(datasourceitem.NumberOfArticles); featuredarticles.MostPopularArticles = datasourceitem.ArticleList.OrderByDescending(x => x.NumberOfViews).Take(datasourceitem.NumberOfArticles); } } return(View(featuredarticles)); }