public ContentResult AddPost(Post post) { string json; ModelState.Clear(); if (TryValidateModel(post)) { var id = _blogRepository.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"); }
/// <summary> /// Adds a new post and returns the id. /// </summary> /// <param name="post"></param> /// <returns>Newly added post id</returns> public int AddPost(Post post) { using (var tran = _session.BeginTransaction()) { _session.Save(post); tran.Commit(); return post.Id; } }
/// <summary> /// Update an existing post. /// </summary> /// <param name="post"></param> public void EditPost(Post post) { using (var tran = _session.BeginTransaction()) { _session.SaveOrUpdate(post); tran.Commit(); } }
public ContentResult EditPost(Post post) { string json; ModelState.Clear(); if (TryValidateModel(post)) { _blogRepository.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"); }
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 }); }