public ActionResult AddSubComment(SubCommentsViewModel subComment, int commentId)
        {
            var userId = this.User.GetUserId();

            this._service.SaveSubComment(userId, subComment, commentId);

            return(RedirectToAction("GetSubComments", "Comments", new { commentId = commentId }));
        }
Example #2
0
        public void SaveSubComment(string userId, SubCommentsViewModel subComment, int commentId)
        {
            SubComment subCommentEntity = null;

            var user    = this.DbContext.Users.FirstOrDefault(u => u.Id == userId);
            var comment = this.DbContext.Comments.FirstOrDefault(p => p.Id == commentId);

            if (subComment != null)
            {
                subCommentEntity = new SubComment
                {
                    CommentMsg    = subComment.CommentMsg,
                    CommentedDate = subComment.CommentedDate,
                };

                if (user != null && comment != null)
                {
                    comment.SubComments.Add(subCommentEntity);
                    user.SubComments.Add(subCommentEntity);

                    this.DbContext.SaveChanges();
                }
            }
        }