示例#1
0
        /// <summary>
        /// 缓存Dictionary<cat_id, NewsCateInfo>对象
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, NewsCateInfo> GetNewsCates()
        {
            object o    = CacheHelper.Cache_Get(Constants.CN_NewsCates_All);
            var    dict = o as Dictionary <string, NewsCateInfo>;

            if (dict != null && dict.Count > 0)
            {
                return(dict);
            }

            Dictionary <string, NewsCateInfo> cates;
            var search = new NewsCateSearchInfo();
            List <NewsCateInfo> list = DataAccess_News.NewsCates_SelectPaged(false);

            cates = new Dictionary <string, NewsCateInfo>(list.Count);
            list.ForEach(t =>
            {
                string cat_id = t.cat_id.ToString();
                if (!cates.ContainsKey(cat_id))
                {
                    cates.Add(cat_id, t);
                }
            });

            CacheHelper.Cache_Store(Constants.CN_NewsCates_All, cates, TimeSpan.FromMinutes(10));
            return(cates);
        }
示例#2
0
        /// <summary>
        /// 获取头条下所有分类 Dictionary<cat_ctrl, NewsCateInfo>
        /// </summary>
        /// <returns></returns>
        public static List <NewsCateInfo> GetCNNewsCates()
        {
            object o = CacheHelper.Cache_Get(Constants.CN_NewsCates);

            if ((o != null) && (o is List <NewsCateInfo>) && (((List <NewsCateInfo>)o).Count > 0))
            {
                return((List <NewsCateInfo>)o);
            }
            List <NewsCateInfo> cates = null;
            List <NewsCateInfo> list  = DataAccess_News.NewsCates_SelectPaged(false);

            cates = new List <NewsCateInfo>(list.Count);
            foreach (NewsCateInfo item in list)
            {
                if (cates.All(i => i.cat_id != item.cat_id))
                {
                    cates.Add(item);
                }
            }
            CacheHelper.Cache_Store(Constants.CN_NewsCates, cates, TimeSpan.FromMinutes(10));
            return(cates);
        }