public ActionResult EditComment(int id, string id2) { CommentBll commentBll = new CommentBll(); if (Session["userId"] == null) { return new ContentResult() { Content = "false" } } ; Models.Comment comment = commentBll.GetCommentById(id); if (comment == null) { return new ContentResult() { Content = "false" } } ; string usernameString = Session["userId"].ToString(); int discriminator = int.Parse(usernameString.Split('-')[0]); string username = usernameString.Split('-')[1]; if (comment.username != username || comment.discriminator != discriminator) { return new ContentResult() { Content = "false" } } ; commentBll.EditCommentById(id, id2); return(new ContentResult() { Content = "true" }); }
public ActionResult DeleteComment(int id) { if (Session["userId"] == null) { //return new ContentResult() { Content = "Not Logged in" }; throw new Exception("Not loged in"); } CommentBll commentBll = new CommentBll(); //List<Models.Comment> comments = commentBll.GetCommentsByVideoId(id2); //Models.Comment comment = comments.Where(x => x.id == id).FirstOrDefault(); Models.Comment comment = commentBll.GetCommentById(id); if (comment == null) { //return new ContentResult() { Content = "Comment not found" }; throw new Exception("Comment does not exist"); } string usernameString = Session["userId"].ToString(); //String text = Request.QueryString.Get("text"); int discriminator = int.Parse(usernameString.Split('-')[0]); string username = usernameString.Split('-')[1]; if (comment.user.username != username || comment.user.discriminator != discriminator) { //return new ContentResult() { Content = "User does not has permission" }; throw new Exception("Not your comment"); } commentBll.DeleteCommentById(id); //comments.Remove(comment); return(new ContentResult() { Content = "Done" }); //return PartialView("CommentSection", comments); //return RedirectToAction("Video", "Home", id); }