Пример #1
0
    /// <summary>
    /// Updates the post.
    /// </summary>
    /// <param name="blogPost">The blog post.</param>
    public void UpdatePost(BlogPost blogPost)
    {
      ExecuteQuery(CACHE_KEY.FormatWith("Post.Update({0}, {1})".FormatWith(blogPost.Id, blogPost.Title)),
        (con) =>
        {
          blogPost.Id = con.Query<int>(Properties.Resources.BlogPost_Update, blogPost).Single();

          // get the tags from the post
          if (!string.IsNullOrWhiteSpace(blogPost.TagText))
          {
            var allTags = con.Query<BlogTag>(Properties.Resources.BlogTags_Get).ToList();

            con.Execute(Properties.Resources.BlogPostTags_Delete, new { PostId = blogPost.Id });
            var tags = blogPost.TagText.Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var tag in tags)
            {
              var dtag = allTags.FirstOrDefault(t => t.Name.ToLower() == tag.ToLower());
              if (dtag == null)
              {
                dtag = new BlogTag { Name = tag };
                dtag.Id = con.Query<int>(Properties.Resources.BlogTag_Update, dtag).Single();
              }
              var bptag = new BlogPostTag { PostId = blogPost.Id, TagId = dtag.Id };
              con.Execute(Properties.Resources.BlogPostTag_Update, bptag);
            }
          }

          // clear the cache
          Cache.RemoveFromCache(CACHE_KEY.FormatWith(".*"));
        });
    }
Пример #2
0
 public BlogPostViewModel(BlogSetting blogSettings, BlogPost post)
   : this()
 {
   BlogSettings = blogSettings;
   Post = post;
 }