public IActionResult UnlikeComment(int CommentId) { int UserId = (int)HttpContext.Session.GetInt32("User"); CommentLiked commentToUnlike = _context.CommentsLiked.FirstOrDefault(cl => cl.UserId == UserId && cl.CommentId == CommentId); _context.Remove(commentToUnlike); _context.SaveChanges(); return(RedirectToAction("TheWall")); }
public IActionResult LikedComment(int CommentId) { int UserId = (int)HttpContext.Session.GetInt32("User"); if (_context.CommentsLiked.Any(c => c.CommentId == CommentId && c.UserId == UserId)) { return(View("MessageBoard")); } else { CommentLiked commentLiked = new CommentLiked(); commentLiked.CommentId = CommentId; commentLiked.UserId = UserId; _context.Add(commentLiked); _context.SaveChanges(); return(RedirectToAction("TheWall")); } }