public virtual void Insert(ContentPost post, string sectionIds, string tagList)
        {
            int[] ids = cvt.ToIntArray(sectionIds);

            post.PageSection    = new ContentSection(); // 不再使用旧版一对多关系
            post.PageSection.Id = ids[0];
            post.insert();


            // 多对多处理
            ContentPostSection ps = new ContentPostSection();

            foreach (int sectionId in ids)
            {
                ContentSection section = new ContentSection();
                section.Id = sectionId;

                ps.Post    = post;
                ps.Section = section;
                ps.insert();
            }

            // 旧版一对多兼容处理
            foreach (int sectionId in ids)
            {
                updateCachePostIds(sectionId);
            }

            post.Tag.Save(tagList);
        }
Esempio n. 2
0
        private void transSectionOne(ContentPost x)
        {
            if (x.PageSection == null || x.PageSection.Id <= 0)
            {
                return;
            }

            int sectionId = x.PageSection.Id;

            ContentPostSection ps = hasTrans(x, sectionId);

            if (ps != null)
            {
                ps.SaveStatus = x.SaveStatus;
                ps.update();
            }
            else
            {
                ContentPostSection newPs = new ContentPostSection();
                newPs.Post       = x;
                newPs.Section    = x.PageSection;
                newPs.SaveStatus = x.SaveStatus;

                newPs.insert();

                logger.Info("transSectionOne=> postId=" + x.Id + ", sectionId=" + x.PageSection.Id);
            }
        }
Esempio n. 3
0
        private void transOne(ContentPost x, List <ContentSection> sections)
        {
            if (sections.Count == 0)
            {
                return;
            }

            // 0. 先更新post
            x.AppId       = sections[0].AppId;
            x.PageSection = sections[0];
            x.update();

            // 1. 删除旧有关系
            ContentPostSection.deleteBatch("PostId=" + x.Id);

            // 2. 挪到新section中
            foreach (ContentSection section in sections)
            {
                // 多对多处理
                ContentPostSection ps = new ContentPostSection();
                ps.Post    = x;
                ps.Section = section;
                ps.insert();
            }
        }
Esempio n. 4
0
        private void transSectionOne( ContentPost x )
        {
            if (x.PageSection == null || x.PageSection.Id <= 0) return;

            int sectionId = x.PageSection.Id;

            ContentPostSection ps = hasTrans( x, sectionId );

            if (ps != null) {

                ps.SaveStatus = x.SaveStatus;
                ps.update();

            }
            else {

                ContentPostSection newPs = new ContentPostSection();
                newPs.Post = x;
                newPs.Section = x.PageSection;
                newPs.SaveStatus = x.SaveStatus;

                newPs.insert();

                logger.Info( "transSectionOne=> postId=" + x.Id + ", sectionId=" + x.PageSection.Id );
            }
        }
Esempio n. 5
0
        public virtual string GetSectionIdsByPost(long postId)
        {
            List <ContentPostSection> list = ContentPostSection.find("PostId=" + postId).list();

            if (list.Count == 0)
            {
                ContentPost post = ContentPost.findById(postId);
                if (post == null)
                {
                    return("");
                }
                if (post.PageSection == null)
                {
                    return("");
                }
                return(post.PageSection.Id.ToString());
            }

            String ids = "";

            foreach (ContentPostSection ps in list)
            {
                ids += ps.Section.Id + ",";
            }

            return(ids.TrimEnd(','));
        }
Esempio n. 6
0
        public virtual void Insert(ContentPost post, string sectionIds, string tagList)
        {
            int[] ids = cvt.ToIntArray(sectionIds);
            if (ids.Length == 0)
            {
                throw new ArgumentException("sectionIds");
            }

            // 保存
            post.PageSection = new ContentSection {
                Id = ids[0]
            };                                                     // 缓存Section
            post.insert();

            // 多对多处理
            ContentPostSection ps = new ContentPostSection();

            foreach (int sectionId in ids)
            {
                ContentSection section = new ContentSection();
                section.Id = sectionId;
                ps.Post    = post;
                ps.Section = section;
                ps.insert();
            }

            // tag
            post.Tag.Save(tagList);
        }
Esempio n. 7
0
        public virtual void DeleteSys(int postId)
        {
            ContentPost post = ContentPost.findById(postId);

            if (post == null)
            {
                return;
            }
            post.SaveStatus = SaveStatus.SysDelete;
            post.update();
            ContentPostSection.updateBatch("SaveStatus=" + SaveStatus.SysDelete, "PostId=" + post.Id);
        }
Esempio n. 8
0
        public virtual void Restore(int id)
        {
            ContentPost post = ContentPost.findById(id);

            if (post == null)
            {
                return;
            }
            post.SaveStatus = SaveStatus.Normal;
            post.update();

            ContentPostSection.updateBatch("SaveStatus=" + SaveStatus.Normal, "PostId=" + post.Id);
        }
Esempio n. 9
0
        public virtual int CountBySection(int sectionId)
        {
            int count = ContentPostSection.count("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal);

            // 兼容旧版
            if (count == 0)
            {
                return(ContentPost.count("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal));
            }
            else
            {
                return(count);
            }
        }
Esempio n. 10
0
        public virtual List <ContentPost> GetBySection(int sectionId, int count)
        {
            List <ContentPostSection> psList = ContentPostSection
                                               .find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal + " order by PostId desc")
                                               .list(count);

            if (psList.Count == 0)
            {
                // 兼容旧版
                return(ContentPost.find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal).list(count));
            }

            return(populatePost(psList));
        }
Esempio n. 11
0
        public virtual DataPage <ContentPost> GetPageBySection(int sectionId, int pageSize)
        {
            DataPage <ContentPostSection> list    = ContentPostSection.findPage("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal + " order by PostId desc", pageSize);
            DataPage <ContentPost>        xResult = list.Convert <ContentPost>(populatePost(list.Results));

            // 兼容旧版
            if (xResult.RecordCount == 0)
            {
                return(ContentPost.findPage("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal, pageSize));
            }
            else
            {
                return(xResult);
            }
        }
Esempio n. 12
0
        public virtual List <ContentPost> GetAllBySection(int sectionId)
        {
            List <ContentPost> xResult = ContentPostSection
                                         .find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal + " order by PostId desc")
                                         .listChildren <ContentPost>("Post");

            if (xResult.Count == 0)
            {
                // 兼容旧版
                return(ContentPost.find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal).list());
            }
            else
            {
                return(xResult);
            }
        }
        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();
        }
Esempio n. 14
0
        public virtual ContentPost GetFirstPost(int appId, int sectionId)
        {
            ContentPostSection xResult = ContentPostSection
                                         .find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal + " order by PostId desc")
                                         .first();

            if (xResult == null)
            {
                // 兼容旧版
                return(ContentPost.find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal).first());
            }
            if (xResult.Post.AppId != appId)
            {
                return(null);
            }
            return(xResult.Post);
        }
Esempio n. 15
0
        private static void insertPostSectionShip(long sectionId, ContentPost post)
        {
            // page section
            ContentSection section = new ContentSection();

            section.Id = sectionId;

            // 缓存原始section
            post.PageSection = section;
            post.update();

            // 多对多关系
            ContentPostSection ps = new ContentPostSection();

            ps.Post    = post;
            ps.Section = section;
            ps.insert();
        }
Esempio n. 16
0
        public virtual int Process(ContentPost post)
        {
            if (post == null)
            {
                return(0);
            }

            int totalCount = 0;

            List <ContentPostSection> psList = ContentPostSection.find("PostId=" + post.Id).list();

            foreach (ContentPostSection x in psList)
            {
                int recordCount = postService.CountBySection(x.Section.Id);

                totalCount += this.ProcessAll(x.Section.Id, recordCount);
            }

            return(totalCount);
        }
        public virtual void Update(ContentPost post, String sectionIds, String tagList)
        {
            if (db.update(post).IsValid)
            {
                post.Tag.Save(tagList);
            }

            List <ContentPostSection> oldPsList = ContentPostSection.find("PostId=" + post.Id).list();

            // 多对多处理
            ContentPostSection.deleteBatch("PostId=" + post.Id);

            ContentPostSection ps = new ContentPostSection();

            int[] ids = cvt.ToIntArray(sectionIds);
            foreach (int sectionId in ids)
            {
                ContentSection section = new ContentSection();
                section.Id = sectionId;

                ps.Post    = post;
                ps.Section = section;
                ps.insert();
            }

            post.PageSection    = new ContentSection(); // 不再使用旧版一对多关系
            post.PageSection.Id = ids[0];
            post.update();


            // 更新旧的section关系
            foreach (ContentPostSection p in oldPsList)
            {
                updateCachePostIds(p.Section.Id);
            }
            // 更新新的section关系
            foreach (int sectionId in ids)
            {
                updateCachePostIds(sectionId);
            }
        }
Esempio n. 18
0
        public virtual List <IBinderValue> GetBySectionIds(String ids, int count)
        {
            String sids = checkIds(ids);

            if (strUtil.IsNullOrEmpty(sids))
            {
                return(new List <IBinderValue>());
            }

            if (count <= 0)
            {
                count = 10;
            }

            List <ContentPostSection> psList = ContentPostSection
                                               .find("SectionId in (" + sids + ") and SaveStatus=" + SaveStatus.Normal)
                                               .list(count);

            List <ContentPost> list = populatePost(psList);

            return(populateBinder(list));
        }
Esempio n. 19
0
        public virtual void Update(ContentPost post, String sectionIds, String tagList)
        {
            // 保存
            if (db.update(post).IsValid)
            {
                post.Tag.Save(tagList);
            }

            // 多对多处理
            ContentPostSection.deleteBatch("PostId=" + post.Id);
            ContentPostSection ps = new ContentPostSection();

            int[] ids = cvt.ToIntArray(sectionIds);
            foreach (int sectionId in ids)
            {
                ContentSection section = new ContentSection();
                section.Id = sectionId;
                ps.Post    = post;
                ps.Section = section;
                ps.insert();
            }
        }
Esempio n. 20
0
 public virtual void DeleteTrueBatch(string ids)
 {
     ContentPost.deleteBatch("Id in (" + ids + ")");
     ContentPostSection.deleteBatch("PostId in  in (" + ids + ")");
 }
Esempio n. 21
0
        public virtual void Insert( ContentPost post, string sectionIds, string tagList )
        {
            int[] ids = cvt.ToIntArray( sectionIds );

            post.PageSection = new ContentSection(); // ����ʹ�þɰ�һ�Զ��ϵ
            post.PageSection.Id = ids[0];
            post.insert();

            // ��Զദ��
            ContentPostSection ps = new ContentPostSection();
            foreach (int sectionId in ids) {

                ContentSection section = new ContentSection();
                section.Id = sectionId;

                ps.Post = post;
                ps.Section = section;
                ps.insert();
            }

            // �ɰ�һ�Զ���ݴ���
            foreach (int sectionId in ids) {
                updateCachePostIds( sectionId );
            }

            post.Tag.Save( tagList );
        }
Esempio n. 22
0
        public virtual void Update( ContentPost post, String sectionIds, String tagList )
        {
            if (db.update( post ).IsValid) {
                post.Tag.Save( tagList );
            }

            List<ContentPostSection> oldPsList = ContentPostSection.find( "PostId=" + post.Id ).list();

            // ��Զദ��
            ContentPostSection.deleteBatch( "PostId=" + post.Id );

            ContentPostSection ps = new ContentPostSection();
            int[] ids = cvt.ToIntArray( sectionIds );
            foreach (int sectionId in ids) {

                ContentSection section = new ContentSection();
                section.Id = sectionId;

                ps.Post = post;
                ps.Section = section;
                ps.insert();
            }

            post.PageSection = new ContentSection(); // ����ʹ�þɰ�һ�Զ��ϵ
            post.PageSection.Id = ids[0];
            post.update();

            // ���¾ɵ�section��ϵ
            foreach (ContentPostSection p in oldPsList) {
                updateCachePostIds( p.Section.Id );
            }
            // �����µ�section��ϵ
            foreach (int sectionId in ids) {
                updateCachePostIds( sectionId );
            }
        }
Esempio n. 23
0
        public virtual void Update( ContentPost post, String sectionIds, String tagList )
        {
            // 保存
            if (db.update( post ).IsValid) {
                post.Tag.Save( tagList );
            }

            // 多对多处理
            ContentPostSection.deleteBatch( "PostId=" + post.Id );
            ContentPostSection ps = new ContentPostSection();
            int[] ids = cvt.ToIntArray( sectionIds );
            foreach (int sectionId in ids) {
                ContentSection section = new ContentSection();
                section.Id = sectionId;
                ps.Post = post;
                ps.Section = section;
                ps.insert();
            }
        }
Esempio n. 24
0
        public virtual void Insert( ContentPost post, string sectionIds, string tagList )
        {
            int[] ids = cvt.ToIntArray( sectionIds );
            if (ids.Length == 0) throw new ArgumentException( "sectionIds" );

            // 保存
            post.PageSection = new ContentSection { Id = ids[0] }; // 缓存Section
            post.insert();

            // 多对多处理
            ContentPostSection ps = new ContentPostSection();
            foreach (int sectionId in ids) {
                ContentSection section = new ContentSection();
                section.Id = sectionId;
                ps.Post = post;
                ps.Section = section;
                ps.insert();
            }

            // tag
            post.Tag.Save( tagList );
        }
Esempio n. 25
0
        private void transOne( ContentPost x, List<ContentSection> sections ) {

            if (sections.Count == 0) return;

            // 0. 先更新post
            x.AppId = sections[0].AppId;
            x.PageSection = sections[0];
            x.update();

            // 1. 删除旧有关系
            ContentPostSection.deleteBatch( "PostId=" + x.Id );

            // 2. 挪到新section中
            foreach (ContentSection section in sections) {

                // 多对多处理
                ContentPostSection ps = new ContentPostSection();
                ps.Post = x;
                ps.Section = section;
                ps.insert();

            }
        }
Esempio n. 26
0
 public virtual void DeleteBatch(string ids)
 {
     ContentPost.updateBatch("set SaveStatus=" + SaveStatus.Delete, "Id in (" + ids + ")");
     ContentPostSection.updateBatch("SaveStatus=" + SaveStatus.Delete, "PostId in(" + ids + ")");
 }
Esempio n. 27
0
 public virtual List <ContentPostSection> GetByPost(long postId)
 {
     return(ContentPostSection.find("PostId=" + postId).list());
 }
Esempio n. 28
0
 private ContentPostSection hasTrans(ContentPost x, int sectionId)
 {
     return(ContentPostSection.find("SectionId=" + sectionId + " and PostId=" + x.Id).first());
 }
Esempio n. 29
0
 public virtual void Delete(ContentPost post)
 {
     post.SaveStatus = SaveStatus.Delete;
     post.update();
     ContentPostSection.updateBatch("SaveStatus=" + SaveStatus.Delete, "PostId=" + post.Id);
 }
Esempio n. 30
0
 public List <ContentPostSection> GetByPost(int postId)
 {
     return(ContentPostSection.find("PostId=" + postId).list());
 }
Esempio n. 31
0
        public virtual void DeleteImg(ContentPost post)
        {
            ContentPostSection.deleteBatch("PostId=" + post.Id);

            db.delete(post);
        }