/// <summary>
        /// 文章分类/标签查找
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public ActionResult SelectArticleForCategory(string category)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();
            IEnumerable <ArticleModel>  Article;

            try
            {
                if (HttpRuntime.Cache["AllArticle_Cache"] != null)
                {
                    var artLists = HttpRuntime.Cache["AllArticle_Cache"] as IEnumerable <ArticleModel>;
                    Article = artLists;
                }
                else
                {
                    //缓存中没有则取数据并写入数据
                    Article = ArticlesSystem.SelectAllArticle();
                    HttpRuntime.Cache.Insert("AllArticle_Cache", Article, null, DateTime.Now.AddMinutes(10),
                                             Cache.NoSlidingExpiration);
                }
                if (Article != null && Article.Any())
                {
                    Article = Article.Where(x => category.Contains(x.BestLabel));
                    dic.Add("Code", "1");
                    dic.Add("Article", Article);
                }
                else
                {
                    dic.Add("Code", "0");
                }
            }
            catch (Exception ex)
            {
                dic.Add("Code", "0");
                dic.Add("Erro", ex.ToString());
            }
            return(Json(dic, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询所有文章
        /// </summary>
        /// <returns></returns>
        //[OutputCache(CacheProfile = "ArticleCacheProfile", VaryByParam = "*")]
        public ActionResult SelectAllArticle(string condition, int pageSize = 1, int pageNum = 5)
        {
            #region MyRegion
            //if (HttpRuntime.Cache["API_Cache_Article" + pIndex + "_pIndex" + pSize + "_pSize" + Category + "_Category"] != null)
            //{
            //    var artLists = HttpRuntime.Cache["API_Cache_Article" + pIndex + "_pIndex" + pSize + "_pSize" + Category + "_Category"] as Dictionary<string, object>;
            //    Result = artLists["artList"] as List<ArticleModel>;

            //}
            //else
            //{
            //    //缓存中没有则取数据并写入数据
            //    Result = ArticlesSystem.SelectAllArticle();
            //    HttpRuntime.Cache.Insert("API_Cache_Article" + pIndex + "_pIndex" + pSize + "_pSize" + Category + "_Category", dics, null, DateTime.Now.AddMinutes(15), Cache.NoSlidingExpiration);
            //}
            #endregion
            var dic = new Dictionary <string, object>();
            IEnumerable <ArticleModel> Article;
            IEnumerable <ArticleModel> ArticlePage;
            try
            {
                if (HttpRuntime.Cache["AllArticle_Cache"] != null)
                {
                    var artLists = HttpRuntime.Cache["AllArticle_Cache"] as IEnumerable <ArticleModel>;
                    Article = artLists;
                }
                else
                {
                    //缓存中没有则取数据并写入数据
                    Article = ArticlesSystem.SelectAllArticle();
                    HttpRuntime.Cache.Insert("AllArticle_Cache", Article, null, DateTime.Now.AddMinutes(5),
                                             Cache.NoSlidingExpiration);
                }

                //热门文章
                var hotArticle = Article.Where(x => x.HotArticles == true).Select(x => new
                {
                    PKID        = x.Pkid,
                    SmallTittle = x.SmallTitlle,
                    ClickCount  = x.ClickCount
                });
                //热门标签
                var hotLabel = Article.Where(e => e.HotArticles == true).Select(x => new
                {
                    BestLabel  = x.BestLabel,
                    LabelCount = Article.Where(z => z.BestLabel == x.BestLabel).Count()
                });
                hotLabel = (from list in hotLabel select list).Distinct();
                //文章类别
                IEnumerable <CategoryListModel> articleCategory;
                if (HttpRuntime.Cache["AllCategory_Cache"] != null)
                {
                    var artLists = HttpRuntime.Cache["AllCategory_Cache"] as IEnumerable <CategoryListModel>;
                    articleCategory = artLists;
                }
                else
                {
                    articleCategory = ArticlesSystem.SelectCategoryList();
                    HttpRuntime.Cache.Insert("AllCategory_Cache", articleCategory, null, DateTime.Now.AddMinutes(5),
                                             Cache.NoSlidingExpiration);
                }

                dic.Add("Code", "1");
                dic.Add("AllArticle", Article);
                dic.Add("hotArticle", hotArticle);
                dic.Add("hotLabel", hotLabel);
                dic.Add("articleCategory", articleCategory.Where(x => x.ParentId == 0));
            }
            catch (Exception ex)
            {
                dic.Add("Code", "0");
                dic.Add("Erro", ex.ToString());
            }
            //return JavaScript(JsonConvert.SerializeObject(dic, new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:mm" }));
            return(Json(dic, JsonRequestBehavior.AllowGet));
        }