Example #1
0
        public async Task <ActionResult> CreateComment(CreateCommentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var comment = new ApplicationComment
                {
                    UserId    = User.Identity.GetUserId(),
                    Comment   = model.Comment,
                    ArticleId = model.ArticleId,
                };

                db.ApplicationComments.Add(comment);
                await db.SaveChangesAsync();
            }
            return(RedirectToAction("Details", "Article", new { id = model.ArticleId }));
        }
Example #2
0
        public async Task <ActionResult> Comment(CommentPostViewModel c)
        {
            if (ModelState.IsValid)
            {
                var model = new ApplicationComment
                {
                    CommentContent = c.Comment,
                    UserId         = c.UserId,
                    PostId         = c.PostId
                };

                db.Comments.Add(model);
                await db.SaveChangesAsync();

                c.PostId = model.Id;
                return(RedirectToAction("Index", "Post", model.PostId));
            }
            return(HttpNotFound());
        }