public ActionResult Post(int id) { using (BlogDb db = new BlogDb()) { Post post = db.Posts.Include(p => p.Comments).FirstOrDefault(p => p.Id == id); // Prevent circular references post.Comments.ForEach(c => c.Post = null); return Json(post, JsonRequestBehavior.AllowGet); } }
public ActionResult AddComment(Comment comment) { Incident.Culture = new CultureInfo("en-US"); using (BlogDb db = new BlogDb()) { db.Comments.Add(comment); comment.Timestamp = DateTime.Now; db.SaveChanges(); } return null; }
public ActionResult Abstracts() { using (BlogDb db = new BlogDb()) { var list = db.Posts.ToList(); foreach (var item in list) { item.Text = item.Text.Split('.').FirstOrDefault() ?? ""; item.Text += "."; } return Json(list, JsonRequestBehavior.AllowGet); } }
public ActionResult Posts() { using (BlogDb db = new BlogDb()) return Json(db.Posts.ToList(), JsonRequestBehavior.AllowGet); }