Пример #1
0
        /// <summary>
        /// Creates a new Post under the given contextpath
        /// </summary>
        /// <param name="actualContextPath">New posts from journal items will be created under contextPath</param>
        /// <param name="text"></param>
        /// <param name="creationDate"></param>
        /// <param name="journalId">The post may be automatically created from a journal item, in this case the journal id is passed</param>
        /// <returns></returns>
        public static GenericContent CreatePost(string contextPath, string text, int journalId, PostType type, Node sharedContent, string details)
        {
            var actualContextPath = contextPath;

            if (type != PostType.BigPost)
            {
                // for journals the context should always be its parent wall workspace. That's where the post will be saved.
                var ws = Workspace.GetWorkspaceWithWallForNode(sharedContent);
                if (ws != null)
                {
                    actualContextPath = ws.Path;
                }
            }
            var postsPath   = RepositoryPath.Combine(actualContextPath, "Posts");
            var postsFolder = Node.LoadNode(postsPath) as GenericContent;

            if (postsFolder == null)
            {
                using (new SystemAccount())
                {
                    var context = Node.LoadNode(actualContextPath);
                    postsFolder        = new GenericContent(context, "Posts");
                    postsFolder.Name   = "Posts";
                    postsFolder.Hidden = true;
                    postsFolder.Save();
                }
            }
            var post = new GenericContent(postsFolder, "Post");

            post.Description    = text;
            post["JournalId"]   = journalId;
            post["PostType"]    = type;
            post["PostDetails"] = details;
            if (sharedContent != null)
            {
                post.SetReference("SharedContent", sharedContent);
            }
            post.Save();
            return(post);
        }