本文整理汇总了C#中Post.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Post.Save方法的具体用法?C# Post.Save怎么用?C# Post.Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FetchEnum_Join_on_a_HasMany_property_should_not_return_duplicate_records
public void FetchEnum_Join_on_a_HasMany_property_should_not_return_duplicate_records()
{
Blog[] blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(0, blogs.Length);
var blog = new Blog() { Name = "Test blog", Author = "Eric Bowen" };
blog.Save();
var post = new Post(blog, "Post1", "Content1", "Category1");
post.Save();
blog.Posts.Add(post);
var post2 = new Post(blog, "Post2", "Content2", "Category2");
post2.Save();
blog.Posts.Add(post2);
blog.Save();
blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(1, blogs.Length);
}
示例2: AnExceptionInvalidatesTheScopeAndPreventItsFlushing
public void AnExceptionInvalidatesTheScopeAndPreventItsFlushing()
{
using (new SessionScope()) {
Post.DeleteAll();
Blog.DeleteAll();
}
Post post;
// Prepare
using(new SessionScope())
{
var blog = new Blog {Author = "hammett", Name = "some name"};
blog.Save();
post = new Post(blog, "title", "contents", "castle");
post.Save();
}
using(var session = new SessionScope())
{
Assert.IsFalse(session.HasSessionError);
Assert.Throws<ActiveRecordException>(() => {
post = new Post(new Blog(100), "title", "contents", "castle");
post.Save();
session.Flush();
});
Assert.IsTrue(session.HasSessionError);
}
}
示例3: Create
public virtual Post Create(Blog blog, String title, String contents, String category)
{
Post post = new Post(blog, title, contents, category);
post.Save();
return post;
}
示例4: CreateAndThrowException
public virtual Post CreateAndThrowException(Blog blog, String title, String contents, String category)
{
Post post = new Post(blog, title, contents, category);
post.Save();
throw new Exception("Dohhh!");
}
示例5: ValidateUser
string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
{
ValidateUser(username, password);
post.Slug = PostHandler.CreateSlug(post.Title);
post.IsPublished = publish;
post.Save();
return post.ID;
}
示例6: Create
public ActionResult Create(FormCollection collection)
{
Post post = new Post();
post.DateAdded = DateTime.Now;
post.Subject = Request.Form["Subject"];
post.Text = Request.Form["Content"]; ;
post.Save();
return Detail(post.Id.ToString());
}
示例7: Init
public new void Init()
{
ActiveRecordStarter.ResetInitializationFlag();
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Blog), typeof(Post));
Recreate();
var blog = new Blog() { Author = "Horatio", Name = "Murmurs" };
blog.Save();
var post = new Post(blog, "To Be Or Not To Be", "Nonsense", "monologues");
post.Save();
}
示例8: LoadPostFileRemoveCommentsAndSaveFile
public void LoadPostFileRemoveCommentsAndSaveFile()
{
const string ExampleFilename = "ExamplePost.xml";
var tempFile = File.CreateText(ExampleFilename);
tempFile.Write(ExampleCommentFileText);
tempFile.Close();
try
{
var post = new Post(new PostFile(ExampleFilename), RemoveChoices.All);
foreach (var comment in post.Comments)
comment.Remove();
post.Save();
}
finally
{
File.Delete(ExampleFilename);
}
}
示例9: Delete
private static void Delete(HttpContext context, Post post)
{
if (!context.User.Identity.IsAuthenticated)
throw new HttpException(403, "No access");
string commentId = context.Request.Form["commentId"];
Comment comment = post.Comments.SingleOrDefault(c => c.ID == commentId);
if (comment != null)
{
post.Comments.Remove(comment);
post.Save();
}
else
{
throw new HttpException(404, "Comment could not be found");
}
}
示例10: CommitVote
public void CommitVote()
{
using(new TransactionScope())
{
var blog = new Blog {Author = "hammett", Name = "some name"};
blog.Save();
var post = new Post(blog, "title", "post contents", "Castle");
post.Save();
// Default to VoteCommit
}
using (new SessionScope()) {
var blogs = Blog.FindAll().ToArray();
Assert.AreEqual(1, blogs.Length);
var posts = Post.FindAll().ToArray();
Assert.AreEqual(1, posts.Length);
}
}
示例11: Delete
private static void Delete(HttpContext context, Post post)
{
if (!context.User.Identity.IsAuthenticated)
throw new HttpException(403, "No access");
string commentId = context.Request["commentId"];
Comment comment = post.Comments.SingleOrDefault(c => c.ID == commentId);
if (comment != null)
{
post.Comments.Remove(comment);
post.Save();
}
else
{
throw new HttpException(404, "Comment could not be found");
}
if (context.Request.HttpMethod == "GET")
{
context.Response.Redirect(post.AbsoluteUrl.ToString() + "#comments", true);
}
}
示例12: NewPost
/// <summary>
/// metaWeblog.newPost
/// </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)
{
ValidateRequest(userName, password);
Post post = new Post();
if (String.IsNullOrEmpty(sentPost.author))
post.Author = userName;
else
post.Author = sentPost.author;
post.Title = sentPost.title;
post.Content = sentPost.description;
post.IsPublished = publish;
post.Slug = sentPost.slug;
post.Description = sentPost.excerpt;
if (sentPost.commentPolicy != "")
{
if (sentPost.commentPolicy == "1")
post.IsCommentsEnabled = true;
else
post.IsCommentsEnabled = false;
}
post.Categories.Clear();
foreach (string item in sentPost.categories)
{
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)
Category newcat = new Category(item, "");
newcat.Save();
post.Categories.Add(newcat);
}
}
post.Tags.Clear();
foreach (string item in sentPost.tags)
{
if (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();
}
示例13: UseBlogWithGenericPostCollection
public void UseBlogWithGenericPostCollection()
{
using (new SessionScope()) {
var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
blog.Save();
var p = new Post(blog, "a", "b", "c");
blog.Posts.Add(p);
p.Save();
var fromDB = Blog.Find(blog.Id);
Assert.AreEqual(1, fromDB.Posts.Count);
}
}
示例14: SlicedOperation
public void SlicedOperation()
{
using (new SessionScope()) {
var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
blog.Save();
var post1 = new Post(blog, "title1", "contents", "category1");
var post2 = new Post(blog, "title2", "contents", "category2");
var post3 = new Post(blog, "title3", "contents", "category3");
post1.Save();
post2.Save();
post3.Published = true;
post3.Save();
var posts = Post.SlicedFindAll(1, 2, Restrictions.Where<Post>(p => p.Blog == blog)).ToArray();
Assert.AreEqual(2, posts.Length);
}
}
示例15: RelationsOneToManyWithWhereAndOrder
public void RelationsOneToManyWithWhereAndOrder()
{
using (new SessionScope()) {
var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
blog.Save();
var post1 = new Post(blog, "title1", "contents", "category1");
var post2 = new Post(blog, "title2", "contents", "category2");
var post3 = new Post(blog, "title3", "contents", "category3");
post1.Published = false;
post2.Published = false;
post3.Published = true;
post1.Save();
Thread.Sleep(1000); // Its a smalldatetime (small precision)
post2.Save();
Thread.Sleep(1000); // Its a smalldatetime (small precision)
post3.Save();
blog = Blog.Find(blog.Id);
blog.Refresh();
Assert.IsNotNull(blog);
Assert.AreEqual(2, blog.UnPublishedPosts.Count);
Assert.AreEqual(1, blog.PublishedPosts.Count);
Assert.AreEqual(3, blog.RecentPosts.Count);
var recentposts = blog.RecentPosts.ToArray();
Assert.AreEqual(post3.Id, recentposts[2].Id);
Assert.AreEqual(post2.Id, recentposts[1].Id);
Assert.AreEqual(post1.Id, recentposts[0].Id);
}
}