Beispiel #1
0
        /// <summary>
        /// App首页瀑布流文章
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task <ActionResult> SelectArticleForAppHomePage(int pageIndex = 1, int pageSize = 30)
        {
            var dic = new Dictionary <string, object>();

            try
            {
                var versionNumber = Request.Headers.Get("VersionCode");
                var version       = Request.Headers.Get("version");

                var pager = new PagerModel {
                    CurrentPage = pageIndex, PageSize = pageSize
                };
                List <DiscoveryModel> articles = null;
                using (var reclient = CacheHelper.CreateCacheClient("SelectArticleForAppHomePage"))
                {
                    var result = await reclient.GetOrSetAsync("AppHomePage/" + pageIndex + "/" + pageSize, () => DiscoverBLL.SelectArticleForAppHomePage(pager), TimeSpan.FromHours(2));

                    if (result.Value != null)
                    {
                        articles = result.Value;
                    }
                    else
                    {
                        articles = await DiscoverBLL.SelectArticleForAppHomePage(pager);
                    }
                }
                pager.TotalItem = 100;
                dic.Add("Code", "1");
                dic.Add("TotalPage", pager.TotalPage);
                dic.Add("TotalCount", pager.TotalItem);
                var articleShowMode = await DistributedCacheHelper.SelectArticleShowMode();

                dic.Add("Articles", articles.Select(article => new
                {
                    ArticleId       = article.PKID,
                    Image           = JsonConvert.DeserializeObject <List <ShowImageModel> >(article.ShowImages).FirstOrDefault().BImage,
                    Title           = article.SmallTitle,
                    ArticleShowMode = articleShowMode,
                    //ContentUrl = ((string.IsNullOrEmpty(versionNumber) == false && (string.Compare(versionNumber, "50") < 0) ||
                    //    (string.IsNullOrEmpty(version) == false && string.Compare(version, "iOS 3.4.5") < 0))) ? article.ContentUrl : DiscoverySite + "/Article/Detail?Id=" + article.RelatedArticleId,
                    //URL = ((string.IsNullOrEmpty(versionNumber) == false && (string.Compare(versionNumber, "50") < 0) ||
                    //    (string.IsNullOrEmpty(version) == false && string.Compare(version, "iOS 3.4.5") < 0))) ? article.ContentUrl : DiscoverySite + "/Article/Detail?Id=" + article.RelatedArticleId
                    ContentUrl = (articleShowMode == "New" || article.Type == 5) ? DomainConfig.FaXian + " /react/findDetail/?bgColor=%23ffffff&textColor=%23333333&id=" + article.PKID : article.ContentUrl,
                    URL        = (articleShowMode == "New" || article.Type == 5) ? DomainConfig.FaXian + "/react/findDetail/?bgColor=%23ffffff&textColor=%23333333&id=" + article.PKID : article.ContentUrl
                }));
            }
            catch (Exception ex)
            {
                WebLog.LogException("App首页瀑布流文章", ex);
                dic.Clear();
                dic.Add("Code", "0");
            }
            return(Json(dic, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public async Task <ActionResult> SelectArticleInfo(string articleId, string userId, int?selectType)
        {
            var dic = new Dictionary <string, object>();

            try
            {
                var articles = await DiscoverBLL.SelectArticleInfo(articleId, userId);

                var versionNumber = Request.Headers.Get("VersionCode");
                var version       = Request.Headers.Get("version");

                var articleShowMode = await DistributedCacheHelper.SelectArticleShowMode();

                //默认返回单条信息
                if (selectType.HasValue == false)
                {
                    var articleInfo = articles.FirstOrDefault();
                    dic.Add("Article", new
                    {
                        PKID            = articleInfo.PKID,
                        ArticleShowMode = articleShowMode,
                        //URL =
                        //((string.IsNullOrEmpty(versionNumber) == false && (string.Compare(versionNumber, "50") < 0) ||
                        //(string.IsNullOrEmpty(version) == false && string.Compare(version, "iOS 3.4.5") < 0))) ? articleInfo.ContentUrl : DiscoverySite + "/Article/Detail?Id=" + articleInfo.RelatedArticleId,
                        URL             = (articleShowMode == "New" || articleInfo.Type == 5) ? DomainConfig.FaXian + "/react/findDetail/?bgColor=%23ffffff&textColor=%23333333&id=" + articleId : articleInfo.ContentUrl,
                        Title           = articleInfo.BigTitle,
                        CommentCount    = articleInfo.CommentCount,
                        VoteCount       = articleInfo.VoteCount,
                        Brief           = articleInfo.Brief,
                        SmallTitle      = articleInfo.SmallTitle,
                        SmallImage      = articleInfo.SmallImage,
                        VoteState       = articleInfo.VoteState,
                        PublishDateTime = articleInfo.PublishDateTime.ToShortDateString(),
                        ClickCount      = articleInfo.ClickCount,
                        Source          = articleInfo.Source
                    });
                }
                else
                {
                    dic.Add("Article", articles.Select(articleInfo => new
                    {
                        PKID            = articleInfo.PKID,
                        URL             = articleInfo.ContentUrl,
                        Title           = articleInfo.BigTitle,
                        CommentCount    = articleInfo.CommentCount,
                        VoteCount       = articleInfo.VoteCount,
                        Brief           = articleInfo.Brief,
                        SmallTitle      = articleInfo.SmallTitle,
                        SmallImage      = articleInfo.SmallImage,
                        VoteState       = articleInfo.VoteState,
                        PublishDateTime = articleInfo.PublishDateTime.ToShortDateString(),
                        ClickCount      = articleInfo.ClickCount,
                        Source          = articleInfo.Source
                    }));
                }
                dic.Add("Code", "1");
            }
            catch (Exception ex)
            {
                WebLog.LogException("查询文章的相关信息(点赞数、评论数)", ex);
                dic.Clear();
                dic.Add("Code", "0");
            }
            return(Json(dic, JsonRequestBehavior.AllowGet));
        }