public ActionResult AddSubComment(SubCommentsVM subComment, int ComID) { var userId = User.Identity.GetUserId(); var user = dbContext.Users.FirstOrDefault(u => u.Id == userId); var comment = dbContext.Comments.FirstOrDefault(p => p.Id == ComID); var subComments = new SubComments(); if (subComment != null) { subComments.CommentMsg = subComment.CommentMsg; subComments.CommentedDate = subComment.CommentedDate; } ; if (user != null && comment != null) { comment.SubComment.Add(subComments); user.SubComments.Add(subComments); dbContext.SaveChanges(); //result = true; } return(RedirectToAction("GetSubComments", "Comments", new { ComID = ComID })); }
public ActionResult AddSubComment(string commentId, string commentText) { SubComments comment = new SubComments(); comment.SCText = commentText; comment.SCCId = Convert.ToInt16(commentId); comment.SCUId = Convert.ToInt16(Session["kullaniciId"]); comment.SCDate = DateTime.Now; comment.SCStatus = true; db.SubComments.Add(comment); db.SaveChanges(); return(Content("Başarılı")); }
public async Task <IActionResult> Comment(CommentViewModel vm) { if (!ModelState.IsValid) { return(RedirectToAction("Post", new { id = vm.PostId })); } var post = _repo.GetPost(vm.PostId); if (vm.MainCommentId > 0) { post.MainComments = post.MainComments ?? new List <MainComments>(); post.MainComments.Add(new MainComments { Message = vm.Message, Created = DateTime.Now, }); _repo.EditPost(post); } else { var comments = new SubComments { MainCommentsId = vm.MainCommentId, Message = vm.Message, Created = DateTime.Now }; } await _repo.SaveChangesAsyc(); return(View()); }
public void AddSubComments(SubComments comment) { _AppContext.SubComments.Add(comment); }