コード例 #1
0
ファイル: HomeViewModel.cs プロジェクト: vfranco2/TidBit
        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");
            }
        }
コード例 #2
0
        /// <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));
        }