Example #1
0
        public async Task <IActionResult> GetBanners()
        {
            var apiMsg = await ApiMessage.Wrap(async() =>
            {
                var topNews      = await contentBusiness.GetLatestNews();
                var topPostEntry = await postEntryBusiness.GetHotPostEntry();
                var bannerList   = await bannersBusienss.GetList() ?? new List <Banners>();
                if (topNews != null)
                {
                    bannerList.Add(new Banners
                    {
                        CreateTime = topNews.CreateTime,
                        Image      = topNews.MediaResource?[0]?.ActualPath,
                        Link       = "news:" + topNews.Id,
                        Title      = topNews.Title
                    });
                }
                if (topPostEntry != null)
                {
                    bannerList.Add(new Banners
                    {
                        CreateTime = topPostEntry.CreateTime,
                        Image      = topPostEntry.PostEntryFileList?[0]?.ActualPath,
                        Link       = "postentry:" + topPostEntry.Id,
                        Title      = topPostEntry.TextContent
                    });
                }
                return(bannerList);
            });

            return(Json(apiMsg));
        }