Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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;
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
 public ActionResult Posts()
 {
     using (BlogDb db = new BlogDb())
         return Json(db.Posts.ToList(), JsonRequestBehavior.AllowGet);
 }