public IActionResult ForumComments(MComment new_comment, int MessageId) { if (ModelState.IsValid) { int?userIndb = HttpContext.Session.GetInt32("UserId"); dbContext.MComments.Add(new_comment); new_comment.UserId = (int)userIndb; new_comment.MessageId = MessageId; dbContext.SaveChanges(); return(Redirect("/forum")); } else { ViewBag.AllMessages = dbContext.Messages .Include(fd => fd.MessageCreator) .Include(ds => ds.PostedComments) .ThenInclude(u => u.MUser) .OrderByDescending(f => f.MessageId) .ToList(); int?userIndb = HttpContext.Session.GetInt32("UserId"); ViewBag.User = dbContext.Users.Include(u => u.MyActions).ThenInclude(b => b.NavMovie).ThenInclude(m => m.Comments).ThenInclude(c => c.NavCUser).FirstOrDefault(u => u.UserId == userIndb); return(View("Forum")); } }
public IActionResult Delete_Comment(int MCommentId) { MComment ToBeDeleted = dbContext.MComments.FirstOrDefault(c => c.MCommentId == MCommentId); dbContext.MComments.Remove(ToBeDeleted); dbContext.SaveChanges(); return(RedirectToAction("Forum")); }
public async Task Delete(MComment c) { var ID = c.CommentID; if (c.UserID == SignedInUser.User.UserID) { await commentService.Remove(ID); await InitComment(); } }