public ActionResult AddPost(string title, string content, string tags) { var success = false; var html = ""; if (Request.IsAuthenticated) { var jss = new JavaScriptSerializer(); var postTags = jss.Deserialize<List<string>>(tags); postTags = postTags.Select(x => x.Trim()).ToList(); var post = new PostModel(User); var newpost = post.AddPost(title, content, postTags); html = RenderPartialToString("~/Views/Blog/BlogPost.cshtml", newpost); success = true; } return new JsonResult { Data = new { success, html }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
public ActionResult EditPost(string title, string content, int postid) { var post = new PostModel(User); var updatedPost = post.EditPost(title, content, postid); return new JsonResult { Data = new { success = true, html = RenderPartialToString("~/Views/Blog/BlogPost.cshtml", updatedPost) } }; }
public ActionResult RemovePost(int? postid) { var success = false; if (postid.HasValue) { var post = new PostModel(User); success = post.RemovePost(postid.Value); } return new JsonResult { Data = new { success } }; }