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"); }
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 }); }
public int AddPost(Post post) { using (var transaction = session.BeginTransaction()) { try { session.Save(post); transaction.Commit(); return post.Id; } catch (Exception) { transaction.Rollback(); throw; } } }