public int Move(ManagedSecurityContext sec, int targetid)
        {
            GetACL().Check(sec, DataOperation.Delete | DataOperation.Create);

            Discussion       target_discussion = Session.Load <Discussion>(targetid);
            DiscussionThread source_thread     = mInstance.DiscussionThread;

            // detach the post from the source thread and reset its parent
            mInstance.DiscussionPostParent = null;

            // create the target thread
            DiscussionThread target_thread = new DiscussionThread();

            target_thread.Created         = mInstance.Created;
            target_thread.Modified        = DateTime.UtcNow;
            target_thread.Discussion      = target_discussion;
            target_thread.DiscussionPosts = new List <DiscussionPost>();
            Session.Save(target_thread);

            // attach the post and all child posts to the target thread
            source_thread.DiscussionPosts.Remove(mInstance);
            mInstance.DiscussionThread = target_thread;
            MoveToDiscussionThread(mInstance, target_thread);

            Save(sec);

            // if this is the last post in the thread, delete the thread
            if (source_thread.DiscussionPosts.Count == 0)
            {
                Session.Delete(source_thread);
            }

            return(target_thread.Id);
        }
 public void AddPostToThreadAddToPostsCollection()
 {
     DiscussionThread thread = new DiscussionThread();
     Assert.AreEqual(0, thread.Posts.Count);
     thread.AddPost(new Post());
     Assert.AreEqual(1, thread.Posts.Count);
 }
        public void ThreadPostsPersistenceByReachability()
        {
            Post             post             = new Post();
            DiscussionThread discussionThread = GetThread_Persistent();

            discussionThread.AddPost(post);

            post.Title   = "First Post";
            post.Content = "Content";
            post.Author  = post.Thread.Forum.Manager;

            UnitOfWork.Current.TransactionalFlush();
            UnitOfWork.CurrentSession.Evict(post);
            UnitOfWork.CurrentSession.Evict(discussionThread);

            Post fromDb = Repository <Post> .Get(post.Id);

            Assert.IsNotNull(fromDb);
            Assert.AreNotSame(post, fromDb);

            DiscussionThread threadFromDb = fromDb.Thread;

            Assert.AreNotSame(discussionThread, threadFromDb);
            Assert.AreEqual(discussionThread.Id, threadFromDb.Id);

            Assert.IsTrue(threadFromDb.Posts.Contains(fromDb));
        }
Beispiel #4
0
        public void AddPostToThreadAddToPostsCollection()
        {
            DiscussionThread thread = new DiscussionThread();

            Assert.AreEqual(0, thread.Posts.Count);
            thread.AddPost(new Post());
            Assert.AreEqual(1, thread.Posts.Count);
        }
Beispiel #5
0
        public void AddPostToThreadSetPostThreadToAddedThread()
        {
            DiscussionThread thread = new DiscussionThread();
            Post             post   = new Post();

            Assert.IsNull(post.Thread);
            thread.AddPost(post);
            Assert.AreEqual(thread, post.Thread);
        }
 public void AddPostToThreadSetPostThreadToAddedThread()
 {
     DiscussionThread thread = new DiscussionThread();
     Post post = new Post();
     Assert.IsNull(post.Thread);
     thread.AddPost(post);
     Assert.AreEqual(thread, post.Thread);
    
 }
Beispiel #7
0
 public ApiModels.Thread Map(DiscussionThread thread)
 {
     return(new ApiModels.Thread
     {
         Id = thread.Id,
         Title = thread.Title,
         Body = thread.Body,
         Created = thread.Created,
         CreatedBy = thread.CreatedBy
     });
 }
        private DiscussionThread GetThread_Persistent()
        {
            Forum            forum = GetForum_Persistent();
            DiscussionThread dt    = new DiscussionThread();

            dt.Title = "First Thread";
            dt.Forum = forum;
            Repository <DiscussionThread> .Save(dt);

            return(dt);
        }
        public void AddingPostToThreadModifyThreadLastUpdateDate()
        {
            DiscussionThread thread = new DiscussionThread();
            thread.LastUpdated = DateTime.Today.AddDays(-3);

            thread.AddPost(new Post());
            Assert.Between(thread.LastUpdated,
                                     DateTime.Now.AddSeconds(-10),
                                     DateTime.Now.AddSeconds(10)
                          );
        }
Beispiel #10
0
        public void AddingPostToThreadModifyThreadLastUpdateDate()
        {
            DiscussionThread thread = new DiscussionThread();

            thread.LastUpdated = DateTime.Today.AddDays(-3);

            thread.AddPost(new Post());
            Assert.Between(thread.LastUpdated,
                           DateTime.Now.AddSeconds(-10),
                           DateTime.Now.AddSeconds(10)
                           );
        }
        public int MoveToDiscussion(ManagedSecurityContext sec, int targetid)
        {
            GetACL().Check(sec, DataOperation.Delete);

            ManagedDiscussion target_discussion = new ManagedDiscussion(Session, targetid);

            target_discussion.GetACL().Check(sec, DataOperation.Create);

            // create the target thread
            DiscussionThread target_thread = new DiscussionThread();

            target_thread.Discussion = target_discussion.Instance;
            target_thread.Modified   = mInstance.Modified;
            target_thread.Created    = mInstance.Created;
            Session.Save(target_thread);
            if (target_discussion.Instance.Modified < mInstance.Modified)
            {
                target_discussion.Instance.Modified = mInstance.Modified;
                Session.Save(target_discussion.Instance);
            }
            // copy the post to a discusison post
            DiscussionPost target_post = new DiscussionPost();

            target_post.AccountId        = mInstance.AccountId;
            target_post.Body             = mInstance.Body;
            target_post.Created          = mInstance.Created;
            target_post.Modified         = mInstance.Modified;
            target_post.Sticky           = false;
            target_post.Subject          = mInstance.Title;
            target_post.DiscussionThread = target_thread;
            Session.Save(target_post);
            // set the new post as parent of all replies
            int comments_discussion_id = ManagedDiscussion.GetOrCreateDiscussionId(
                Session, typeof(AccountBlogPost).Name, mInstance.Id, sec);
            Discussion comments_discussion = Session.Load <Discussion>(comments_discussion_id);

            foreach (DiscussionThread thread in Collection <DiscussionThread> .GetSafeCollection(comments_discussion.DiscussionThreads))
            {
                foreach (DiscussionPost post in thread.DiscussionPosts)
                {
                    post.DiscussionThread = target_thread;
                    if (post.DiscussionPostParent == null)
                    {
                        post.DiscussionPostParent = target_post;
                    }
                }
                Session.Delete(thread);
            }
            // delete the current post that became a discussion post
            Session.Delete(mInstance);
            return(target_post.Id);
        }
 private void MoveToDiscussionThread(DiscussionPost post, DiscussionThread thread)
 {
     foreach (DiscussionPost child in post.DiscussionPosts)
     {
         child.DiscussionThread.DiscussionPosts.Remove(child);
         child.DiscussionThread = thread;
         if (thread.DiscussionPosts == null)
         {
             thread.DiscussionPosts = new List <DiscussionPost>();
         }
         thread.DiscussionPosts.Add(child);
         MoveToDiscussionThread(child, thread);
     }
 }
        public int MoveToAccountBlog(ManagedSecurityContext sec, int targetid)
        {
            GetACL().Check(sec, DataOperation.Delete);

            ManagedAccountBlog blog = new ManagedAccountBlog(Session, targetid);

            blog.GetACL().Check(sec, DataOperation.Create);

            // copy the post to a blog post
            AccountBlogPost t_post = new AccountBlogPost();

            t_post.AccountBlog    = Session.Load <AccountBlog>(targetid);
            t_post.AccountId      = mInstance.AccountId;
            t_post.EnableComments = true;
            t_post.Created        = mInstance.Created;
            t_post.Modified       = mInstance.Modified;
            t_post.Title          = mInstance.Subject;
            t_post.Body           = mInstance.Body;
            t_post.AccountName    = ManagedAccount.GetAccountNameWithDefault(Session, mInstance.AccountId);
            Session.Save(t_post);

            // move the comments thread to the blog comments
            int        discussion_id     = ManagedDiscussion.GetOrCreateDiscussionId(Session, "AccountBlogPost", t_post.Id, sec);
            Discussion target_discussion = Session.Load <Discussion>(discussion_id);

            // create the target thread
            DiscussionThread target_thread = new DiscussionThread();

            target_thread.Created    = mInstance.Created;
            target_thread.Modified   = mInstance.DiscussionThread.Modified;
            target_thread.Discussion = target_discussion;
            Session.Save(target_thread);

            // attach the post and all child posts to the target thread
            MoveToDiscussionThread(mInstance, target_thread);

            // nullify each child's parent
            foreach (DiscussionPost post in mInstance.DiscussionPosts)
            {
                post.DiscussionPostParent = null;
            }

            // delete the current post that became a blog entry
            Session.Delete(mInstance);
            return(t_post.Id);
        }
        public void CanSaveDiscussionThread()
        {
            Forum forum = GetForum_Persistent();
            DiscussionThread dt = new DiscussionThread();
            dt.Title = "First Thread";
            dt.Forum = forum;
            Repository<DiscussionThread>.Save(dt);

            UnitOfWork.Current.TransactionalFlush();
            UnitOfWork.CurrentSession.Evict(dt);

            DiscussionThread fromDb = Repository<DiscussionThread>.Get(dt.Id);
            Assert.AreNotSame(dt, fromDb);
            Assert.AreEqual("First Thread", fromDb.Title);
            Assert.Between(dt.LastUpdated,
                           DateTime.Now.AddSeconds(-10),
                           DateTime.Now.AddSeconds(10)
                );
            Assert.AreEqual(dt.Id, fromDb.Id);
        }
        public void CanSaveDiscussionThread()
        {
            Forum            forum = GetForum_Persistent();
            DiscussionThread dt    = new DiscussionThread();

            dt.Title = "First Thread";
            dt.Forum = forum;
            Repository <DiscussionThread> .Save(dt);

            UnitOfWork.Current.TransactionalFlush();
            UnitOfWork.CurrentSession.Evict(dt);

            DiscussionThread fromDb = Repository <DiscussionThread> .Get(dt.Id);

            Assert.AreNotSame(dt, fromDb);
            Assert.AreEqual("First Thread", fromDb.Title);
            Assert.Between(dt.LastUpdated,
                           DateTime.Now.AddSeconds(-10),
                           DateTime.Now.AddSeconds(10)
                           );
            Assert.AreEqual(dt.Id, fromDb.Id);
        }
Beispiel #16
0
 public override void ProcessResponse(string resp)
 {
     Result = Deserialize <List <DiscussionThread> >(resp, "threadedDiscussions")[0];
 }
 private DiscussionThread GetThread_Persistent()
 {
     Forum forum = GetForum_Persistent();
     DiscussionThread dt = new DiscussionThread();
     dt.Title = "First Thread";
     dt.Forum = forum;
     Repository<DiscussionThread>.Save(dt);
     return dt;
 }