本文整理汇总了C#中Blog.Update方法的典型用法代码示例。如果您正苦于以下问题:C# Blog.Update方法的具体用法?C# Blog.Update怎么用?C# Blog.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blog
的用法示例。
在下文中一共展示了Blog.Update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleOperations3
public void SimpleOperations3()
{
using (new SessionScope()) {
var blogs = Blog.FindAll().ToArray();
Assert.IsNotNull(blogs);
Assert.AreEqual(10, blogs.Length);
var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
blog.Create();
blogs = Blog.FindAll().ToArray();
Assert.AreEqual(blog.Name, blogs[10].Name);
Assert.AreEqual(blog.Author, blogs[10].Author);
Assert.IsNotNull(blogs);
Assert.AreEqual(11, blogs.Length);
blog.Name = "something else1";
blog.Author = "something else2";
blog.Update();
blogs = Blog.FindAll().ToArray();
Assert.IsNotNull(blogs);
Assert.AreEqual(11, blogs.Length);
blog = blogs.Last();
Assert.AreEqual(blog.Name, blog.Name);
Assert.AreEqual(blog.Author, blog.Author);
}
}
示例2: LinqSimpleOperations2
public void LinqSimpleOperations2()
{
using (new SessionScope()) {
var blogs = Blog.All;
Assert.IsNotNull(blogs);
Assert.AreEqual(10, blogs.Count());
var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
blog.Create();
Assert.AreEqual(11, (from b in Blog.All select b).Count());
blogs = Blog.All.OrderByDescending(b => b.Id);
Assert.AreEqual(blog.Name, blogs.First().Name);
Assert.AreEqual(blog.Author, blogs.First().Author);
blog.Name = "something else1";
blog.Author = "something else2";
blog.Update();
blogs = Blog.All.OrderByDescending(b => b.Id);
Assert.IsNotNull(blogs);
Assert.AreEqual(11, Blog.All.Count());
Assert.AreEqual(blog.Name, blogs.First().Name);
Assert.AreEqual(blog.Author, blogs.First().Author);
}
}
示例3: SimpleOperations2
public void SimpleOperations2()
{
Blog[] blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(0, blogs.Length);
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Create();
blogs = Blog.FindAll();
Assert.AreEqual(blog.Name, blogs[0].Name);
Assert.AreEqual(blog.Author, blogs[0].Author);
Assert.IsNotNull(blogs);
Assert.AreEqual(1, blogs.Length);
blog.Name = "something else1";
blog.Author = "something else2";
blog.Update();
blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(1, blogs.Length);
Assert.AreEqual(blog.Name, blogs[0].Name);
Assert.AreEqual(blog.Author, blogs[0].Author);
}
示例4: SimpleOperations2
public void SimpleOperations2()
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
using (new SessionScope())
{
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
var blogs = Blog.Queryable;
Assert.IsNotNull(blogs);
Assert.AreEqual(0, blogs.Count());
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Create();
Assert.AreEqual(1, (from b in Blog.Queryable select b).Count());
blogs = Blog.Queryable;
Assert.AreEqual(blog.Name, blogs.First().Name);
Assert.AreEqual(blog.Author, blogs.First().Author);
blog.Name = "something else1";
blog.Author = "something else2";
blog.Update();
blogs = Blog.Queryable;
Assert.IsNotNull(blogs);
Assert.AreEqual(1, Blog.Queryable.Count());
Assert.AreEqual(blog.Name, blogs.First().Name);
Assert.AreEqual(blog.Author, blogs.First().Author);
}
}
示例5: PostBlog
public IHttpActionResult PostBlog(BlogModel blog)
{
// Validate request
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Get the blog information from the blog website
// If unable to get the information, do not create the blog record
BlogInfo blogInfo = _wordPressBlogReader.VerifyBlog(blog.Link);
if (blogInfo == null)
{
return NotFound();
}
//Set the blog description and title that was obtained from the blog website
blog.Description = blogInfo.Description;
blog.Title = blogInfo.Title;
// Set blog as not approved
blog.Approved = false;
//Set up new Blog object, populated from input blog
Blog dbBlog = new Blog();
dbBlog.Update(blog);
// Add the new Blog object to the DB
_blogRepository.Add(dbBlog);
// Save the changes in the database
try
{
_unitOfWork.Commit();
}
catch (Exception e)
{
throw new Exception("Unable to add the blog to the database", e);
}
// Set blog ID in BlogModel object with the ID
// that was placed in the DB blog after it was added to DB
blog.BlogID = dbBlog.BlogID;
// Return the created blog record
return CreatedAtRoute("DefaultApi", new { id = blog.BlogID }, blog);
}