public JsonResult AddComment(string body, int id)
        {
            var nComment = new Comment
            {
                Body = body,
                AuthorId = User.Identity.GetUserId(),
                CommentTypeId = 4,
                EntityId = id,
                PostedDate = DateTime.Now
            };

            db.Comments.Add(nComment);
            db.SaveChanges();

            return Json(new { result = true });
        }
示例#2
0
        public JsonResult AddComment(string body, int id)
        {
            var nComment = new Comment
            {
                Body = body,
                AuthorId = User.Identity.GetUserId(),
                CommentTypeId = 1,
                EntityId = id,
                PostedDate = DateTime.Now
            };

            var article = db.NewsArticles.Find(id);
            article.NumberOfComments++;

            db.Comments.Add(nComment);
            db.SaveChanges();

            return Json(new {result = true});
        }