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")); }
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")); }
/// <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(); } }
public int AddPost(PostName post) { using (var tran = _sess.BeginTransaction()) { _sess.Save(post); tran.Commit(); return(post.Id); } }
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 } )); }