Exemplo n.º 1
0
        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);
        }