public AkismetStatus ProcessComment()
        {
            var akismetEnabled = _settingsRepository.BlogAkismetEnabled;
            var deleteSpam     = _settingsRepository.BlogAkismetDeleteSpam;
            var akismetStatus  = new AkismetStatus();

            if (akismetEnabled && !_requestData.IsAuthenticated)
            {
                /* If the url or akismet key is invalid, this part
                 * might throw an exception. If it does, the comment
                 * is swallowed, as we do not know the status of the
                 * comment. If it happens, just correct the url or the
                 * key and you should be fine!
                 *
                 * */

                var comment          = AkismetComment.Create(_commentEntity, _requestData);
                var akistmetPipeline = new AkismetPipeline(_akismetService);

                try
                {
                    akismetStatus = akistmetPipeline.Process(comment, _settingsRepository);

                    if (akismetStatus.IsSpam && !deleteSpam)
                    {
                        _commentEntity.CommentStatus = 2; // its spam
                        _commentRepository.AddComment(_commentEntity);
                    }
                    else if (akismetStatus.IsHam)
                    {
                        _commentEntity.CommentStatus = 0;
                        _commentRepository.AddComment(_commentEntity);
                    }
                }
                catch (Exception exception)
                {
                    _error.InsertException(exception);
                }
            }
            else
            {
                // submit the comment, mark as approved if the user is logged in
                _commentEntity.CommentStatus = _requestData.IsAuthenticated ? 0 : 1;
                _commentRepository.AddComment(_commentEntity);
            }

            return(akismetStatus);
        }
Esempio n. 2
0
        public IActionResult OnPost()
        {
            Comment.UserID     = UsersProfile;
            Comment.UserPostID = LoggedInUser;

            commentInterface.AddComment(Comment);
            return(RedirectToPage("/Userpage/VisitUsersProfile", UsersProfile.Id));
        }
Esempio n. 3
0
        public ActionResult AddComment(CommentDto dto)
        {
            var comment = new Comment
            {
                PostId  = dto.PostId,
                UserId  = dto.CommenterId,
                Content = dto.Message,
                Created = DateTime.Now
            };

            _commentService.AddComment(comment);
            return(Ok());
        }
Esempio n. 4
0
        public async Task <Comment> AddComment(Guid id, string userId, CommentViewModel comment)
        {
            Comment com = new Comment
            {
                Id       = Guid.NewGuid(),
                UserId   = userId,
                Text     = comment.Text,
                Title    = comment.Title,
                CourseId = id,
                Modified = DateTime.Now,
            };

            await _commentRepository.AddComment(com);

            return(com);
        }
        public IActionResult AddComment(SortTextUser model)
        {
            if (ModelState.IsValid)
            {
                var newModel = new Comment()
                {
                    State  = 0,
                    Text   = model.Content,
                    TextId = model.Id,
                    UserId = (int)HttpContext.Session.GetInt32("UserId"),
                    Time   = DateTime.Now
                };
                _comment.AddComment(newModel);
                ViewBag.Message = "Success";

                TempData["TextId"] = model.Id.ToString();
                return(RedirectToAction("Index"));
            }

            return(View("Index"));
        }
        public IActionResult Post([FromBody] Comment comment)
        {
            if (comment == null)
            {
                return(BadRequest());
            }

            var user = User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (user == null)
            {
                return(Unauthorized());
            }

            comment.Owner     = Guid.Parse(user);
            comment.TimeStamp = DateTime.Now;

            var savedComment = _commentRepo.AddComment(comment);

            return(CreatedAtAction(nameof(GetById), new { Id = savedComment.Id }, savedComment));
        }
Esempio n. 7
0
 public IActionResult Index(string commentFullName, string commentMail, string commentContent, int articleId)
 {
     commentContext.AddComment(commentFullName, commentMail, commentContent, articleId);
     return(Redirect("/Article/Index/" + articleId));
 }