Subtext.Framework.XmlRpc.MetaWeblog.editPost C# (CSharp) Method

editPost() public method

public editPost ( string postid, string username, string password, Subtext.Framework.XmlRpc.Post post, bool publish ) : bool
postid string
username string
password string
post Subtext.Framework.XmlRpc.Post
publish bool
return bool
        public bool editPost(string postid, string username, string password, Post post, bool publish)
        {
            Framework.BlogInfo info = Config.CurrentBlog;
            ValidateUser(username, password, info.AllowServiceAccess);

            Entry entry = Entries.GetEntry(Int32.Parse(postid), PostConfig.None, true);
            if (entry != null)
            {
                entry.Author = info.Author;
                entry.Email = info.Email;
                entry.Body = post.description;
                entry.Title = post.title;
                entry.Description = string.Empty;
                entry.IncludeInMainSyndication = true;

                entry.Categories.Clear();
                if (post.categories != null)
                    entry.Categories.AddRange(post.categories);

                entry.PostType = PostType.BlogPost;
                //User trying to change future dating.

                DateTime dateTimeInPost = Config.CurrentBlog.TimeZone.ToLocalTime(post.dateCreated);

                if (dateTimeInPost > Config.CurrentBlog.TimeZone.Now && publish)
                {
                    entry.DateSyndicated = dateTimeInPost;
                }
                entry.IsActive = publish;

                entry.DateModified = Config.CurrentBlog.TimeZone.Now;
                int[] categoryIds = { };
                if (entry.Categories.Count > 0)
                {
                    categoryIds = Entries.GetCategoryIdsFromCategoryTitles(entry);
                }

                if (!string.IsNullOrEmpty(post.wp_slug))
                {
                    entry.EntryName = post.wp_slug;
                }

                Entries.Update(entry);
                Entries.SetEntryCategoryList(entry.Id, categoryIds);

                if (entry.Enclosure == null)
                {
                    if (!string.IsNullOrEmpty(post.enclosure.url))
                    {
                        Components.Enclosure enc = new Components.Enclosure();
                        enc.Url = post.enclosure.url;
                        enc.MimeType = post.enclosure.type;
                        enc.Size = post.enclosure.length;
                        enc.EntryId = entry.Id;
                        Enclosures.Create(enc);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(post.enclosure.url))
                    {
                        Components.Enclosure enc = entry.Enclosure;
                        enc.Url = post.enclosure.url;
                        enc.MimeType = post.enclosure.type;
                        enc.Size = post.enclosure.length;
                        Enclosures.Update(enc);
                    }
                    else
                    {
                        Enclosures.Delete(entry.Enclosure.Id);
                    }
                }
            }
            return false;
        }

Usage Example

Example #1
0
        public void CanUpdatePostWithCategories()
        {
            string hostname = UnitTestHelper.GenerateRandomString();
            Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, ""));
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "");
            Config.CurrentBlog.AllowServiceAccess = true;

            string category1Name = UnitTestHelper.GenerateRandomString();
            string category2Name = UnitTestHelper.GenerateRandomString();
            UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category1Name);
            UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, category2Name);

            Entry entry = new Entry(PostType.BlogPost);
            entry.Title = "Title 1";
            entry.Body = "Blah";
            entry.IsActive = true;
            entry.DateCreated = entry.DateSyndicated = entry.DateModified = DateTime.ParseExact("1975/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture);
            entry.Categories.Add(category1Name);
            int entryId = Entries.Create(entry);

            MetaWeblog api = new MetaWeblog();
            Post post = new Post();
            post.title = "Title 2";
            post.description = "Blah";
            post.categories = new string[] { category2Name };
            post.dateCreated = DateTime.Now;

            bool result = api.editPost(entryId.ToString(CultureInfo.InvariantCulture), "username", "password", post, true);

            entry = Entries.GetEntry(entryId, PostConfig.None, true);
            Assert.AreEqual(1, entry.Categories.Count, "We expected one category. We didn't get what we expected.");
            Assert.AreEqual(category2Name, entry.Categories[0], "Category has not been updated correctly.");
        }
All Usage Examples Of Subtext.Framework.XmlRpc.MetaWeblog::editPost