private void bindLink(IBlock block, String lbl, object obj)
        {
            OpenComment c = (OpenComment)obj;

            block.Set("c.sContent", strUtil.CutString(c.Content, 100));

            Type targetType = Entity.GetType(c.TargetDataType);

            IEntity parent = ndb.findById(targetType, c.TargetDataId);

            if (parent == null)
            {
                block.Set("c.TargetTitle", "");
                block.Set("c.Link", "#");
            }
            else
            {
                Object title = parent.get("Title");
                block.Set("c.TargetTitle", title);

                IAppData objP  = (IAppData)parent;
                String   clink = objP == null ? "#" : alink.ToAppData(objP);
                block.Set("c.Link", clink);
            }
        }
        private void saveComment(Microblog oBlog, String content)
        {
            User    creator = oBlog.Creator;
            IMember owner   = User.findById(oBlog.OwnerId);

            OpenComment c = new OpenComment();

            c.Content   = content;
            c.TargetUrl = MbLink.ToShowFeed(oBlog.User, oBlog.Id);

            c.TargetDataType = oBlog.GetType().FullName;
            c.TargetDataId   = oBlog.Id;


            c.TargetTitle  = string.Format("(微博{0}){1}", oBlog.Created.ToShortDateString(), strUtil.ParseHtml(oBlog.Content, 25));
            c.TargetUserId = oBlog.User.Id;

            c.OwnerId = owner.Id;
            c.AppId   = 0;
            c.FeedId  = oBlog.Id;

            c.Ip       = oBlog.Ip;
            c.Author   = creator.Name;
            c.ParentId = 0;
            c.AtId     = 0;

            c.Member = creator;

            commentService.Create(c);
        }
Exemple #3
0
        private void importPrivate(long startId, long endId)
        {
            IList clist = ndb.find(commentType, "Id>=" + startId + " and Id<=" + endId + " order by Id asc").list();

            logger.Info("old comment count=" + clist.Count);

            foreach (IComment x in clist)
            {
                // 如果已经导入,那么就删除已有的OpenComment
                OpenComment oc = hasImport(x);

                if (oc != null)
                {
                    deleteOpenComment(oc);
                    deleteTransLog(oc);
                }

                OpenComment comment = getOpenComment(x);

                OpenCommentService service = ObjectContext.Create <OpenCommentService>();
                service.Import(comment);

                logTransInfo(x, comment);
            }
        }
Exemple #4
0
        private OpenComment getOpenComment(IComment x)
        {
            OpenComment comment = new OpenComment();

            comment.AppId = x.AppId;

            comment.Title   = x.Title;
            comment.Content = x.Content;

            comment.Author  = x.Author;
            comment.Member  = x.Member;
            comment.Ip      = x.Ip;
            comment.Created = x.Created;

            comment.ParentId = getParentId(x);

            IEntity p = ndb.findById(targetType, x.RootId);

            if (p == null)
            {
                comment.TargetDataId   = 0;
                comment.TargetDataType = targetType.FullName;
                comment.TargetTitle    = "--null-";
                comment.TargetUserId   = 0;
            }
            else
            {
                comment.TargetDataId   = p.Id;
                comment.TargetDataType = targetType.FullName;
                comment.TargetTitle    = getTitle(p);
                comment.TargetUserId   = getCreatorId(p);
            }

            return(comment);
        }
Exemple #5
0
        private void updateComment(object[] args, object target)
        {
            ForumPost  post   = args[0] as ForumPost;
            User       editor = args[1] as User;
            ForumTopic topic  = ForumTopic.findById(post.TopicId);

            // 更新评论
            CommentSync objSync = CommentSync.find("PostId=" + post.Id).first();

            if (objSync == null)
            {
                return;
            }
            OpenComment comment = objSync.Comment;

            comment.Content = strUtil.ParseHtml(post.Content);
            comment.update();

            // 更新此ForumPost对应的Microblog
            Microblog mblog = Microblog.find("DataId=:id and DataType=:dtype")
                              .set("id", post.Id)
                              .set("dtype", typeof(ForumPost).FullName)
                              .first();

            if (mblog != null)
            {
                mblog.Content = getPostContent(post);
                mblog.update();
            }
        }
Exemple #6
0
        private void bindSingleInfo(Boolean canAdmin, IBlock block, OpenComment c)
        {
            Dictionary <String, String> userInfo = getUserInfo(c.Member, c.Author);

            block.Set("c.UserName", userInfo["userName"]);
            block.Set("c.AuthorText", userInfo["authorText"]);
            block.Set("c.UserFace", userInfo["userFace"]);

            block.Set("c.Created", c.Created);
            block.Set("c.Content", getContent(c));
            block.Set("c.Id", c.Id);
            block.Set("c.ParentId", c.ParentId);
            block.Set("c.Replies", c.Replies);

            if (canAdmin)
            {
                String deleteLink = to(Delete, c.Id);
                block.Set("c.DeleteLink", deleteLink);
                block.Set("hideClass", "");
            }
            else
            {
                block.Set("hideClass", "hide");
            }
        }
Exemple #7
0
 public void Delete( OpenComment c )
 {
     if (c == null) return;
     db.delete( c );
     deleteSubComments( c );
     updateRootTargetReplies( c );
 }
Exemple #8
0
        private void bindSubList(IBlock block, OpenComment comment, List <OpenComment> lists, Boolean canAdmin)
        {
            foreach (OpenComment c in lists)
            {
                bindSingleInfo(canAdmin, block, c);

                block.Next();
            }
        }
Exemple #9
0
        private void logTransInfo(IComment x, OpenComment comment)
        {
            OpenCommentTrans trans = new OpenCommentTrans();

            trans.CommentId     = x.Id;
            trans.CommentType   = x.GetType().FullName;
            trans.OpenCommentId = comment.Id;

            trans.insert();
        }
Exemple #10
0
        // TODO 罗列子列表
        private String getContent(OpenComment c)
        {
            //if (c.ParentId == 0) return c.Content;
            //IComment parent = commentService.GetById( c.ParentId, ctx.app.Id );
            //if (parent == null) return c.Content;
            //String quote = "<div class=\"quote\"><span class=\"qSpan\">{0} : {1}</span></div>";
            //return string.Format( quote, parent.Author, strUtil.CutString( parent.Content, 50 ) ) + "<div>" + c.Content + "</div>";

            return(c.Content);
        }
        public virtual void Create()
        {
            String userName;
            if (ctx.viewer.IsLogin) {
                userName = ctx.viewer.obj.Name;
            }
            else {
                userName = ctx.Post( "UserName" );
                if (strUtil.IsNullOrEmpty( userName )) errors.Add( lang( "exRequireAuthor" ) );
                if (strUtil.HasText( userName ) && userName.Length < 2) errors.Add( lang( "exAuthorShort" ) );
            }

            if (ctx.viewer.IsLogin == false) Html.Captcha.CheckError( ctx );

            String content = strUtil.CutString( ctx.Post( "Content" ), config.Instance.Site.CommentLength );
            if (strUtil.IsNullOrEmpty( content )) errors.Add( lang( "exRequireContent" ) );
            if (strUtil.HasText( content ) && content.Length < 3) errors.Add( lang( "exContentShort" ) );
            if (getContentTip().Equals( content )) errors.Add( lang( "exRequireContent" ) );

            if (ctx.HasErrors) {
                echoError();
                return;
            }

            OpenComment c = new OpenComment();
            c.Content = content;
            c.TargetUrl = ctx.Post( "url" );
            c.TargetDataType = ctx.Post( "dataType" );
            c.TargetDataId = ctx.PostLong( "dataId" );
            c.TargetTitle = ctx.Post( "dataTitle" );
            c.TargetUserId = ctx.PostLong( "dataUserId" );

            c.OwnerId = ctx.PostLong( "ownerId" );
            c.AppId = ctx.PostLong( "appId" );
            c.FeedId = ctx.PostLong( "feedId" );

            c.Ip = ctx.Ip;
            c.Author = userName;
            c.AuthorEmail = ctx.Post( "UserEmail" );
            c.ParentId = ctx.PostLong( "ParentId" );
            c.AtId = ctx.PostLong( "AtId" );

            if (ctx.viewer.IsLogin) {
                c.Member = (User)ctx.viewer.obj;
            }

            Result result = commentService.Create( c );

            if (result.IsValid) {
                echoAjaxOk();
            }
            else {
                echoError( result );
            }
        }
Exemple #12
0
        public void UpdateComments()
        {
            BlogApp app = BlogApp.findById(this.AppId);

            if (app == null)
            {
                return;
            }
            app.CommentCount = OpenComment.count("AppId=" + this.AppId + " and TargetDataType='" + this.GetType().FullName + "'");
            app.update();
        }
 public virtual Result CreateNoNotification( OpenComment c )
 {
     Result result = c.insert();
     if (result.IsValid) {
         updateParentReplies( c );
         updateRootTargetReplies( c );
         return result;
     }
     else {
         return result;
     }
 }
Exemple #14
0
        private OpenComment hasImport(IComment x)
        {
            OpenCommentTrans trans = OpenCommentTrans.find("CommentId=:cid and CommentType=:ctype")
                                     .set("cid", x.Id)
                                     .set("ctype", commentType.FullName)
                                     .first();

            if (trans == null)
            {
                return(null);
            }

            return(OpenComment.findById(trans.OpenCommentId));
        }
Exemple #15
0
        private void deleteCommentByPost(ForumPost post)
        {
            CommentSync objSync = CommentSync.find("PostId=" + post.Id).first();

            if (objSync == null)
            {
                return;
            }

            // 删除此评论
            OpenComment comment = objSync.Comment;

            commentService.Delete(comment);

            // 删除同步表 CommentSync
            objSync.delete();
        }
Exemple #16
0
        private void addComment(object[] args, object target)
        {
            ForumPost  post    = args[0] as ForumPost;
            ForumTopic topic   = ForumTopic.findById(post.TopicId);
            User       creator = args[1] as User;
            IMember    owner   = args[2] as IMember;
            IApp       app     = args[3] as IApp;

            OpenComment c = new OpenComment();

            c.Content   = strUtil.ParseHtml(post.Content);
            c.TargetUrl = alink.ToAppData(topic);

            c.TargetDataType = typeof(ForumTopic).FullName;
            c.TargetDataId   = topic.Id;
            c.TargetTitle    = topic.Title;
            c.TargetUserId   = topic.Creator.Id;

            c.OwnerId = owner.Id;
            c.AppId   = app.Id;
            c.FeedId  = getFeedId(topic);

            c.Ip       = post.Ip;
            c.Author   = creator.Name;
            c.ParentId = 0;
            c.AtId     = 0;

            c.Member = creator;

            Result result = commentService.CreateNoNotification(c);

            // 修复comment额外的replies更新
            IForumTopicService topicService = ObjectContext.Create <IForumTopicService>(typeof(ForumTopicService));

            topic.Replies = topicService.CountReply(post.TopicId);
            topic.update("Replies");

            // 同步表
            CommentSync x = new CommentSync();

            x.Post    = post;
            x.Comment = result.Info as OpenComment;
            x.insert();
        }
Exemple #17
0
        private void deletePost(object[] args, object target)
        {
            OpenComment comment = args[0] as OpenComment;

            CommentSync objSync = CommentSync.find("CommentId=" + comment.Id).first();

            if (objSync == null)
            {
                return;
            }

            // 删除帖子
            postService.DeleteToTrash(objSync.Post, comment.Member, "");

            // 删除同步表
            objSync.delete();

            // 删除 ForumPost 对应的 Microblog
        }
Exemple #18
0
        public virtual void Delete(long id)
        {
            OpenComment c = commentService.GetById(id);

            if (c == null)
            {
                echoText("数据不存在");
                return;
            }

            if (checkAdminPermission(c.TargetDataType, c.TargetDataId) == false)
            {
                echoText("没有权限");
                return;
            }

            commentService.Delete(c);
            echoAjaxOk();
        }
Exemple #19
0
        private void addPost(object[] args, object target)
        {
            OpenComment comment = args[0] as OpenComment;

            if (comment == null || comment.Id <= 0)
            {
                return;
            }

            // 只监控论坛评论,其他所有评论跳过
            if (comment.TargetDataType != typeof(ForumTopic).FullName)
            {
                return;
            }

            // 附属信息
            ForumTopic topic   = commentService.GetTarget(comment) as ForumTopic;
            User       creator = comment.Member;
            IMember    owner   = getOwner(topic);
            IApp       app     = ForumApp.findById(topic.AppId);

            // 内容
            ForumPost post = new ForumPost();

            post.ForumBoardId = topic.ForumBoard.Id;
            post.TopicId      = topic.Id;
            post.ParentId     = getParentId(comment, topic);
            post.Title        = "re:" + topic.Title;
            post.Content      = comment.Content;
            post.Ip           = comment.Ip;


            // 保存
            // 因为comment本身已有通知,所以论坛不再发通知
            postService.InsertNoNotification(post, creator, owner, app);

            // 同步表
            CommentSync objSync = new CommentSync();

            objSync.Post    = post;
            objSync.Comment = comment;
            objSync.insert();
        }
Exemple #20
0
        private int getParentId(OpenComment comment, ForumTopic topic)
        {
            ForumPost post = postService.GetPostByTopic(topic.Id);

            // 获取topic对应的post的Id
            if (comment.ParentId == 0)
            {
                return(post.Id);
            }
            else
            {
                CommentSync objSync = CommentSync.find("CommentId=" + comment.ParentId).first();
                if (objSync == null || objSync.Post == null)
                {
                    return(post.Id);
                }

                return(objSync.Post.Id);
            }
        }
        private void addComment( object[] args, object target ) {

            ForumPost post = args[0] as ForumPost;
            ForumTopic topic = ForumTopic.findById( post.TopicId );
            User creator = args[1] as User;
            IMember owner = args[2] as IMember;
            IApp app = args[3] as IApp;

            OpenComment c = new OpenComment();
            c.Content = strUtil.ParseHtml( post.Content );
            c.TargetUrl = alink.ToAppData( topic );

            c.TargetDataType = typeof( ForumTopic ).FullName;
            c.TargetDataId = topic.Id;
            c.TargetTitle = topic.Title;
            c.TargetUserId = topic.Creator.Id;

            c.OwnerId = owner.Id;
            c.AppId = app.Id;
            c.FeedId = getFeedId( topic );

            c.Ip = post.Ip;
            c.Author = creator.Name;
            c.ParentId = 0;
            c.AtId = 0;

            c.Member = creator;

            Result result = commentService.CreateNoNotification( c );

            // 修复comment额外的replies更新
            IForumTopicService topicService = ObjectContext.Create<IForumTopicService>( typeof( ForumTopicService ) );
            topic.Replies = topicService.CountReply( post.TopicId );
            topic.update( "Replies" );

            // 同步表
            CommentSync x = new CommentSync();
            x.Post = post;
            x.Comment = result.Info as OpenComment;
            x.insert();
        }
Exemple #22
0
        public void Import()
        {
            List <TComment> clist = db.findAll <TComment>();

            foreach (TComment x in clist)
            {
                // 如果已经导入,那么就删除已有的OpenComment
                OpenComment oc = hasImport(x);
                if (oc != null)
                {
                    deleteOpenComment(oc);
                    deleteTransLog(oc);
                }

                OpenComment comment = getOpenComment(x);

                OpenCommentService service = ObjectContext.Create <OpenCommentService>();
                service.Import(comment);

                logTransInfo(x, comment);
            }
        }
        private void saveComment( Microblog oBlog, String content )
        {
            User creator = oBlog.Creator;
            IMember owner = User.findById( oBlog.OwnerId );

            OpenComment c = new OpenComment();
            c.Content = content;
            c.TargetUrl = Link.To( oBlog.User, Show, oBlog.Id );

            c.TargetDataType = oBlog.DataType;
            c.TargetDataId = oBlog.DataId;
            c.TargetTitle = string.Format( "(微博{0}){1}", oBlog.Created.ToShortDateString(), strUtil.ParseHtml( oBlog.Content, 25 ) );
            c.TargetUserId = oBlog.User.Id;

            c.OwnerId = owner.Id;
            c.AppId = 0;
            c.FeedId = oBlog.Id;

            c.Ip = oBlog.Ip;
            c.Author = creator.Name;
            c.ParentId = 0;
            c.AtId = 0;

            c.Member = creator;

            commentService.Create( c );
        }
Exemple #24
0
        public virtual IEntity GetTarget( OpenComment c )
        {
            if (strUtil.IsNullOrEmpty( c.TargetDataType )) return null;
            if (c.TargetDataId <= 0) return null;

            Type targetType = Entity.GetType( c.TargetDataType );
            if (targetType == null) return null;
            return ndb.findById( targetType, c.TargetDataId );
        }
Exemple #25
0
        // TODO 罗列子列表
        private String getContent( OpenComment c )
        {
            //if (c.ParentId == 0) return c.Content;
            //IComment parent = commentService.GetById( c.ParentId, ctx.app.Id );
            //if (parent == null) return c.Content;
            //String quote = "<div class=\"quote\"><span class=\"qSpan\">{0} : {1}</span></div>";
            //return string.Format( quote, parent.Author, strUtil.CutString( parent.Content, 50 ) ) + "<div>" + c.Content + "</div>";

            return c.Content;
        }
Exemple #26
0
        private void bindSubList( IBlock block, OpenComment comment, List<OpenComment> lists, Boolean canAdmin )
        {
            foreach (OpenComment c in lists) {

                bindSingleInfo( canAdmin, block, c );

                block.Next();

            }
        }
Exemple #27
0
        private void bindSingleInfo( Boolean canAdmin, IBlock block, OpenComment c )
        {
            Dictionary<String, String> userInfo = getUserInfo( c.Member, c.Author );

            block.Set( "c.UserName", userInfo["userName"] );
            block.Set( "c.AuthorText", userInfo["authorText"] );
            block.Set( "c.UserFace", userInfo["userFace"] );

            block.Set( "c.Created", c.Created );
            block.Set( "c.Content", getContent( c ) );
            block.Set( "c.Id", c.Id );
            block.Set( "c.ParentId", c.ParentId );
            block.Set( "c.Replies", c.Replies );

            if (canAdmin) {
                String deleteLink = to( Delete, c.Id );
                block.Set( "c.DeleteLink", deleteLink );
                block.Set( "hideClass", "" );
            }
            else {
                block.Set( "hideClass", "hide" );
            }
        }
 private static Microblog getFeed( OpenComment c )
 {
     if (c.FeedId > 0) {
         return Microblog.findById( c.FeedId );
     }
     else {
         return Microblog.find( "DataId=:id and DataType=:dtype" )
             .set( "id", c.TargetDataId )
             .set( "dtype", c.TargetDataType )
             .first();
     }
 }
Exemple #29
0
        private void sendNotificationToRoot( List<int> sentIds, OpenComment c )
        {
            if (c.Member != null && c.Member.Id == c.TargetUserId) return; // 不用给自己发通知
            int receiverId = c.TargetUserId;
            if (sentIds.Contains( receiverId )) return; // 已经发过,不用重发

            String msg = c.Author + " 回复了你的 <a href=\"" + c.TargetUrl + "\">" + c.TargetTitle + "</a> ";

            nfService.send( receiverId, typeof( User ).FullName, msg, NotificationType.Comment );
            sentIds.Add( receiverId );
        }
Exemple #30
0
        private List<OpenComment> getSubListFromTotal( OpenComment parent, List<OpenComment> totalSubList )
        {
            List<OpenComment> results = new List<OpenComment>();
            int iCount = 0;
            foreach (OpenComment c in totalSubList) {

                if (iCount >= OpenComment.subCacheSize) break;

                if (c.ParentId == parent.Id) {
                    results.Add( c );
                    iCount = iCount + 1;
                }
            }

            return results;
        }
Exemple #31
0
        private void sendNotifications( OpenComment c )
        {
            List<int> sentIds = new List<int>();

            if (c.ParentId > 0) {
                OpenComment p = OpenComment.findById( c.ParentId );
                if (p != null && p.Member != null) {
                    sendNotificationsTo( sentIds, p, c );
                }
            }

            if (c.AtId > 0) {
                OpenComment at = OpenComment.findById( c.AtId );
                if (at != null && at.Member != null) {
                    sendNotificationsTo( sentIds, at, c );
                }
            }

            if (c.TargetUserId > 0) {
                sendNotificationToRoot( sentIds, c );
            }
        }
Exemple #32
0
 private void deleteSubComments( OpenComment c )
 {
     if (c.Replies == 0) return;
     db.deleteBatch<OpenComment>( "ParentId=" + c.Id );
 }
Exemple #33
0
        private static void updateTargetReplies( OpenComment c, int replies )
        {
            Type targetType = Entity.GetType( c.TargetDataType );
            ICommentTarget target = ndb.findById( targetType, c.TargetDataId ) as ICommentTarget;
            if (target == null) return;
            target.Replies = replies;
            db.update( target );

            if (c.AppId <= 0) return;
            Type appType = target.GetAppType();
            if (appType == null) return;

            ICommentApp app = ndb.findById( appType, c.AppId ) as ICommentApp;
            if (app == null) return;
            int appCount = OpenComment.count( "AppId=" + c.AppId + " and TargetDataType='" + c.TargetDataType + "'" );
            app.CommentCount = appCount;
            db.update( app );
        }
Exemple #34
0
        private static void updateParentReplies( OpenComment c )
        {
            if (c.ParentId == 0) return;

            OpenComment p = OpenComment.findById( c.ParentId );
            if (p == null) {
                c.ParentId = 0;
                c.update();
                return;
            }

            //------------------------------------------------
            p.Replies = OpenComment.count( "ParentId=" + p.Id );

            //-------------------------------------------------
            List<OpenComment> subFirst = OpenComment.find( "ParentId=" + p.Id + " order by Id asc" ).list( OpenComment.subCacheSize );
            List<OpenComment> subLast = OpenComment.find( "ParentId=" + p.Id + " order by Id desc" ).list( OpenComment.subCacheSize );

            p.FirstReplyIds = strUtil.GetIds( subFirst );
            p.LastReplyIds = strUtil.GetIds( subLast );

            p.update();
        }
Exemple #35
0
 private static void updateTargetReplies( OpenComment c, int replies )
 {
     Type targetType = Entity.GetType( c.TargetDataType );
     ICommentTarget target = ndb.findById( targetType, c.TargetDataId ) as ICommentTarget;
     if (target == null) return;
     target.Replies = replies;
     db.update( target );
 }
Exemple #36
0
        private void updateRootTargetReplies( OpenComment c )
        {
            int replies;
            OpenCommentCount objCount;

            if (c.TargetDataId > 0 && strUtil.HasText( c.TargetDataType )) {
                replies = OpenComment.find( "TargetDataType=:dtype and TargetDataId=" + c.TargetDataId )
                    .set( "dtype", c.TargetDataType )
                    .count();

                objCount = OpenCommentCount.find( "DataType=:dtype and DataId=" + c.TargetDataId )
                    .set( "dtype", c.TargetDataType )
                    .first();
            }
            else {

                if (c.TargetUrl == null) {
                    replies = 0;
                    objCount = null;
                }
                else {

                    replies = OpenComment.find( "TargetUrl=:url" )
                        .set( "url", c.TargetUrl )
                        .count();

                    objCount = OpenCommentCount.find( "TargetUrl=:url" )
                        .set( "url", c.TargetUrl )
                        .first();

                }
            }

            if (objCount == null) {
                insertCommentCount( c, replies );
            }
            else {
                updateCommentCount( objCount, replies );
            }

            updateTargetReplies( c, replies );
        }
Exemple #37
0
        public virtual void Create()
        {
            String userName;

            if (ctx.viewer.IsLogin)
            {
                userName = ctx.viewer.obj.Name;
            }
            else
            {
                userName = ctx.Post("UserName");
                if (strUtil.IsNullOrEmpty(userName))
                {
                    errors.Add(lang("exRequireAuthor"));
                }
                if (strUtil.HasText(userName) && userName.Length < 2)
                {
                    errors.Add(lang("exAuthorShort"));
                }
            }

            if (ctx.viewer.IsLogin == false)
            {
                Html.Captcha.CheckError(ctx);
            }

            String content = strUtil.CutString(ctx.Post("Content"), config.Instance.Site.CommentLength);

            if (strUtil.IsNullOrEmpty(content))
            {
                errors.Add(lang("exRequireContent"));
            }
            if (strUtil.HasText(content) && content.Length < 3)
            {
                errors.Add(lang("exContentShort"));
            }
            if (getContentTip().Equals(content))
            {
                errors.Add(lang("exRequireContent"));
            }

            if (ctx.HasErrors)
            {
                echoError();
                return;
            }

            OpenComment c = new OpenComment();

            c.Content        = content;
            c.TargetUrl      = ctx.Post("url");
            c.TargetDataType = ctx.Post("dataType");
            c.TargetDataId   = ctx.PostLong("dataId");
            c.TargetTitle    = ctx.Post("dataTitle");
            c.TargetUserId   = ctx.PostLong("dataUserId");

            c.OwnerId = ctx.PostLong("ownerId");
            c.AppId   = ctx.PostLong("appId");
            c.FeedId  = ctx.PostLong("feedId");

            c.Ip          = ctx.Ip;
            c.Author      = userName;
            c.AuthorEmail = ctx.Post("UserEmail");
            c.ParentId    = ctx.PostLong("ParentId");
            c.AtId        = ctx.PostLong("AtId");

            if (ctx.viewer.IsLogin)
            {
                c.Member = (User)ctx.viewer.obj;
            }

            Result result = commentService.Create(c);

            if (result.IsValid)
            {
                echoAjaxOk();
            }
            else
            {
                echoError(result);
            }
        }
 public virtual IEntity GetTarget( OpenComment c )
 {
     Type targetType = Entity.GetType( c.TargetDataType );
     return ndb.findById( targetType, c.TargetDataId );
 }
Exemple #39
0
 private void deleteTransLog(OpenComment oc)
 {
     OpenCommentTrans.deleteBatch("OpenCommentId=" + oc.Id);
 }
        private void updateTargetReplies( OpenComment c, int replies )
        {
            //Type targetType = Entity.GetType( c.TargetDataType );
            ICommentTarget target = GetTarget( c ) as ICommentTarget;
            if (target != null) {
                target.Replies = replies;
                db.update( target );
            }

            // feed replies
            Microblog mblog = getFeed( c );
            if (mblog != null) {
                mblog.Replies = replies;
                mblog.update();
            }

            if (c.AppId > 0 && target != null) {
                Type appType = target.GetAppType();
                if (appType != null) {

                    ICommentApp app = ndb.findById( appType, c.AppId ) as ICommentApp;
                    if (app != null) {
                        int appCount = OpenComment.count( "AppId=" + c.AppId + " and TargetDataType='" + c.TargetDataType + "'" );
                        app.CommentCount = appCount;
                        db.update( app );
                    }
                }
            }
        }
Exemple #41
0
        private void deleteOpenComment(OpenComment x)
        {
            OpenCommentService service = ObjectContext.Create <OpenCommentService>();

            service.Delete(x);
        }
Exemple #42
0
 // 只是导入,并不发送通知
 public Result Import( OpenComment c )
 {
     Result result = c.insert();
     if (result.IsValid) {
         updateParentReplies( c );
         updateRootTargetReplies( c );
         return result;
     }
     else {
         return result;
     }
 }
Exemple #43
0
        private int getParentId( OpenComment comment, ForumTopic topic )
        {
            ForumPost post = postService.GetPostByTopic( topic.Id );

            // 获取topic对应的post的Id
            if (comment.ParentId == 0) {
                return post.Id;
            }
            else {

                CommentSync objSync = CommentSync.find( "CommentId=" + comment.ParentId ).first();
                if (objSync == null || objSync.Post == null) return post.Id;

                return objSync.Post.Id;

            }
        }
Exemple #44
0
        private static void insertCommentCount( OpenComment c, int replies )
        {
            OpenCommentCount objCount = new OpenCommentCount();
            objCount.TargetUrl = c.TargetUrl;
            objCount.DataType = c.TargetDataType;
            objCount.DataId = c.TargetDataId;
            objCount.Replies = replies;

            objCount.insert();
        }