示例#1
0
        public ContentResult AddPost(PostName post)
        {
            string json;

            ModelState.Clear();

            if (TryValidateModel(post))
            {
                var id = repo.AddPost(post);

                json = JsonConvert.SerializeObject(new
                {
                    id      = id,
                    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
        public ContentResult EditPost(PostName post)
        {
            string json;

            ModelState.Clear();

            if (TryValidateModel(post))
            {
                repo.EditPost(post);
                json = JsonConvert.SerializeObject(new
                {
                    id      = post.Id,
                    success = true,
                    message = "Changes saved successfully."
                });
            }
            else
            {
                json = JsonConvert.SerializeObject(new
                {
                    id      = 0,
                    success = false,
                    message = "Failed to save the changes."
                });
            }

            return(Content(json, "application/json"));
        }
示例#3
0
 /// <summary>
 /// Update an existing post.
 /// </summary>
 /// <param name="post"></param>
 public void EditPost(PostName post)
 {
     using (var tran = _sess.BeginTransaction())
     {
         _sess.SaveOrUpdate(post);
         tran.Commit();
     }
 }
示例#4
0
 public int AddPost(PostName post)
 {
     using (var tran = _sess.BeginTransaction())
     {
         _sess.Save(post);
         tran.Commit();
         return(post.Id);
     }
 }
示例#5
0
 public static MvcHtmlString PostLink(this HtmlHelper help, PostName pname)
 {
     return(help.ActionLink(pname.TitleName, "Post", "Blognew",
                            new
     {
         year = pname.PostedDate.Year,
         month = pname.PostedDate.Month,
         title = pname.UrlName
     },
                            new
     {
         title = pname.TitleName
     }
                            ));
 }