public virtual List <ContentPost> GetTopBySectionAndCategory(int sectionId, int categoryId, int appId, int count)
        {
            List <ContentPost> list;

            // 兼容旧版
            ContentSection s = ContentSection.findById(sectionId);

            if (strUtil.IsNullOrEmpty(s.CachePostIds))
            {
                list = ContentPost.find("AppId=" + appId + " and PageSection.Id=" + sectionId + " and CategoryId=" + categoryId + " and SaveStatus=" + SaveStatus.Normal + " order by Id desc").list(count);
            }
            else
            {
                //list = ContentPost.findBySql( "select top " + count + " from ContentPost a, ContentSection b where a.AppId=" + appId + " and a.SectionId=" + sectionId + " and a.CategoryId=" + categoryId + " and a.SaveStatus=" + SaveStatus.Normal + " and b.SectionId=" + sectionId );

                list = new List <ContentPost>();
                List <ContentPost> posts = ContentPost.find("Id in (" + s.CachePostIds + ") and SaveStatus=" + SaveStatus.Normal).list();
                foreach (ContentPost p in posts)
                {
                    if (p.CategoryId == categoryId)
                    {
                        list.Add(p);
                    }
                }
            }

            list.Sort();

            return(list);
        }
        private void updateCachePostIds(int sectionId)
        {
            ContentSection section = ContentSection.findById(sectionId);

            if (section == null)
            {
                throw new NullReferenceException();
            }

            // 为了兼容旧版,section和post一对多关系下的数据也要抓取
            List <ContentPostSection> list  = ContentPostSection.find("SectionId=" + sectionId).list(section.ListCount);
            List <ContentPost>        posts = ContentPost.find("SectionId=" + sectionId).list(section.ListCount);
            List <int> idList = getRecentIds(list, posts);

            section.CachePostIds = getCacheIds(idList, section.ListCount);
            section.update();
        }
        public virtual List <ContentPost> GetBySection(int appId, int sectionId, int count)
        {
            List <ContentPost> list;

            // 兼容旧版
            ContentSection s = ContentSection.findById(sectionId);

            if (strUtil.IsNullOrEmpty(s.CachePostIds))
            {
                list = ContentPost.find("AppId=" + appId + " and PageSection.Id=" + sectionId + " and SaveStatus=" + SaveStatus.Normal + " order by Id desc").list(count);
            }
            else
            {
                list = ContentPost.find("Id in (" + s.CachePostIds + ") and SaveStatus=" + SaveStatus.Normal).list();
            }

            list.Sort();
            return(list);
        }
Exemple #4
0
        public virtual List <ContentPost> GetTopBySectionAndCategory(int sectionId, int categoryId)
        {
            ContentSection s = ContentSection.findById(sectionId);

            return(GetTopBySectionAndCategory(sectionId, categoryId, s.ListCount));
        }
Exemple #5
0
        //---------------------------------------------------------------------------------------------


        public virtual List <ContentPost> GetBySection(int sectionId)
        {
            ContentSection s = ContentSection.findById(sectionId);

            return(this.GetBySection(sectionId, s.ListCount));
        }