Sitecore.Modules.WeBlog.MetaBlogApi.newPost C# (CSharp) Method

newPost() private method

private newPost ( string blogid, string username, string password, CookComputing.XmlRpc.XmlRpcStruct rpcstruct, bool publish ) : string
blogid string
username string
password string
rpcstruct CookComputing.XmlRpc.XmlRpcStruct
publish bool
return string
        public string newPost(string blogid, string username, string password, XmlRpcStruct rpcstruct, bool publish)
        {
            Authenticate(username, password);
            CheckUserRights(blogid, username);

            var entryTitleRaw = rpcstruct["title"];
            if (entryTitleRaw == null)
                throw new ArgumentException("'title' must be provided");

            var entryTitle = entryTitleRaw.ToString();
            var currentBlog = GetContentDatabase().GetItem(blogid);

            if (currentBlog != null)
            {
                BlogHomeItem blogItem = currentBlog;
                var template = new TemplateID(blogItem.BlogSettings.EntryTemplateID);
                var newItem = ItemManager.AddFromTemplate(entryTitle, template, currentBlog);

                SetItemData(newItem, rpcstruct);

                if (publish)
                    ContentHelper.PublishItemAndRequiredAncestors(newItem.ID);

                return newItem.ID.ToString();
            }
            else
                return string.Empty;
        }

Usage Example

示例#1
0
        public void NewPost_ValidUser()
        {
            var entryContent = new XmlRpcStruct();

            entryContent.Add("title", "the title");
            entryContent.Add("description", "the description");

            var newId = m_api.newPost(m_blog1.ID.ToString(), m_userAuthor.Name, PASSWORD, entryContent, false);

            Assert.IsNotNullOrEmpty(newId);

            var newItem = m_blog1.Database.GetItem(newId);

            try
            {
                Assert.AreEqual("the title", newItem["title"]);
                Assert.AreEqual("the description", newItem["content"]);
            }
            finally
            {
                using (new SecurityDisabler())
                {
                    newItem.Delete();
                }
            }
        }