本文整理汇总了C#中Post.CanPublish方法的典型用法代码示例。如果您正苦于以下问题:C# Post.CanPublish方法的具体用法?C# Post.CanPublish怎么用?C# Post.CanPublish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post.CanPublish方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewPost
/// <summary>
/// metaWeblog.newPost method
/// </summary>
/// <param name="blogId">
/// always 1000 in BlogEngine since it is a singlar blog instance
/// </param>
/// <param name="userName">
/// login username
/// </param>
/// <param name="password">
/// login password
/// </param>
/// <param name="sentPost">
/// struct with post details
/// </param>
/// <param name="publish">
/// mark as published?
/// </param>
/// <returns>
/// postID as string
/// </returns>
internal string NewPost(string blogId, string userName, string password, MWAPost sentPost, bool publish)
{
if (!Security.IsAuthorizedTo(Rights.CreateNewPosts))
{
throw new MetaWeblogException("11", "User authentication failed");
}
string author = String.IsNullOrEmpty(sentPost.author) ? userName : sentPost.author;
var post = new Post
{
Author = author,
Title = sentPost.title,
Content = sentPost.description,
IsPublished = publish,
Slug = sentPost.slug,
Description = sentPost.excerpt
};
if (publish)
{
if (!post.CanPublish(author))
{
throw new MetaWeblogException("11", "Not authorized to publish this Post.");
}
}
if (sentPost.commentPolicy != string.Empty)
{
post.HasCommentsEnabled = sentPost.commentPolicy == "1";
}
post.Categories.Clear();
foreach (var item in sentPost.categories.Where(c => c != null && c.Trim() != string.Empty))
{
Category cat;
if (LookupCategoryGuidByName(item, out cat))
{
post.Categories.Add(cat);
}
else
{
// Allowing new categories to be added. (This breaks spec, but is supported via WLW)
var newcat = new Category(item, string.Empty);
newcat.Save();
post.Categories.Add(newcat);
}
}
post.Tags.Clear();
foreach (var item in sentPost.tags.Where(item => item != null && item.Trim() != string.Empty))
{
post.Tags.Add(item);
}
if (sentPost.postDate != new DateTime())
{
post.DateCreated = sentPost.postDate;
}
post.Save();
return post.Id.ToString();
}