You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a requirements, that editing post in WLW, the pubDate must stay same as it was initially.
For example I need to edit some post from year 2010 and I need that the published date is staying unchanged. At the moment it is possible only in web-page. In WLW I need to enter each time published date, because it is not loaded into WLW.
I came up with solution to change the code. Can you suggest, is there any better way to do that.
I changed 3 things:
Post.cs:
public Post()
{
ID = Guid.NewGuid().ToString();
Title = "My new post";
Author = HttpContext.Current.User.Identity.Name;
Content = "the content";
//default datetime only if new posting from web
if (Blog.IsNewPost)
{
PubDate = DateTime.UtcNow;
}
LastModified = DateTime.UtcNow;
Categories = new string[0];
Comments = new List<Comment>();
IsPublished = true;
Latitude = "";
Longtitude = "";
Place = "";
}
MetaWebLogHandler.cs
string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
{
ValidateUser(username, password);
if (!string.IsNullOrWhiteSpace(post.Slug))
{
post.Slug = PostHandler.CreateSlug(post.Slug);
}
else
{
post.Slug = PostHandler.CreateSlug(post.Title);
}
//in case new post from WLW and pubdate is empty
if (post.PubDate == DateTime.MinValue)
{
post.PubDate = DateTime.UtcNow;
}
post.IsPublished = publish;
Storage.Save(post);
return post.ID;
}
MetaWebLogHandler.cs
bool IMetaWeblog.UpdatePost(string postid, string username, string password, Post post, bool publish)
{
ValidateUser(username, password);
Post match = Storage.GetAllPosts().FirstOrDefault(p => p.ID == postid);
if (match != null)
{
match.Title = post.Title;
match.Excerpt = post.Excerpt;
match.Content = post.Content;
//if posting date is not empty (published date is marked in WLW)
if (post.PubDate != DateTime.MinValue)
{
match.PubDate = post.PubDate;
}
if (!string.Equals(match.Slug, post.Slug, StringComparison.OrdinalIgnoreCase))
match.Slug = PostHandler.CreateSlug(post.Slug);
match.Categories = post.Categories;
match.IsPublished = publish;
Storage.Save(match);
}
return match != null;
}
The text was updated successfully, but these errors were encountered:
The changes you've made to IMetaWeblog.UpdatePost allow you to change the publication date, the code as originally stated did not change match,PubDate so it didn't matter what WLW said it would remain the same
Interesting. Based on my testing, when you open old post in WLW, the PublishedDate checkbox is not set and the date is empty.
After clicking publish, the post will take current date.
I will make some additional testing.
I have a requirements, that editing post in WLW, the pubDate must stay same as it was initially.
For example I need to edit some post from year 2010 and I need that the published date is staying unchanged. At the moment it is possible only in web-page. In WLW I need to enter each time published date, because it is not loaded into WLW.
I came up with solution to change the code. Can you suggest, is there any better way to do that.
I changed 3 things:
The text was updated successfully, but these errors were encountered: