コード例 #1
0
        public ContentResult AddPost(Post post)
        {
            string json;

            ModelState.Clear();

            if (ModelState.IsValid)
            {
                var postId = blogRepository.AddPost(post);

                json = JsonConvert.SerializeObject(new
                    {
                        id = postId,
                        success = true,
                        message = "Post added successfully."
                    });
            }
            else
            {
                json = JsonConvert.SerializeObject(new
                {
                    id = 0,
                    success = false,
                    message = "Failed to add the post."
                });
            }

            return Content(json, "application/json");
        }
コード例 #2
0
ファイル: ActionLinkHelper.cs プロジェクト: Beton/Blog4Net
 public static MvcHtmlString PostLink(this HtmlHelper helper, Post post)
 {
     return helper.ActionLink(post.Title, "Post", "Blog",
                              new
                                  {
                                      year = post.PostedOn.Year,
                                      month = post.PostedOn.Month,
                                      title = post.UrlSlug
                                  },
                              new
                                  {
                                      title = post.Title
                                  });
 }
コード例 #3
0
 public int AddPost(Post post)
 {
     using (var transaction = session.BeginTransaction())
     {
         try
         {
             session.Save(post);
             transaction.Commit();
             return post.Id;
         }
         catch (Exception)
         {
             transaction.Rollback();
             throw;
         }
     }
 }