예제 #1
0
        public virtual ActionResult AddAnonymousArticleComment(AddAnonymousCommentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(MVC.Comment.Views._AddAnonymousPageComment, model));
            }
            var newComment = new Comment
            {
                AddedDate = DateAndTime.GetDateTime(),
                Body      = model.Body.ToSafeHtml(),
                LikeCount = 0
            };

            if (model.ReplyId != null)
            {
                newComment.Parent = _commentService.Find(model.ReplyId.Value);
            }

            newComment.AnonymousUser = new AnonymousUser
            {
                Email = model.Email,
                Name  = model.Name,
                IP    = Request.ServerVariables["REMOTE_ADDR"]
            };

            newComment.Article = _articleService.Find(model.Id);
            _commentService.AddComment(newComment);
            _uow.SaveChanges();

            if (model.ReplyId != null)
            {
                _emailService.SendCommentReplyNotification(new CommentReplyEmailNotificationData
                {
                    CommentId    = newComment.Id,
                    CommentText  = newComment.Body,
                    FromUserName = model.Name,
                    PostId       = newComment.Article.Id,
                    PostTitle    = newComment.Article.Title,
                    ToUserName   = newComment.Parent.User.UserName,
                    ToEmail      = newComment.Parent.User.Email
                }, CommentReplyType.ReplyToArticleComment);
            }

            bool sendData = newComment.IsApproved = !_optionService.ModeratingComment;

            if (sendData)
            {
                return(Json(new
                {
                    show = "true",
                    name = model.Name,
                    date = DateAndTime.ConvertToPersian(newComment.AddedDate),
                    likeCount = ConvertToPersian.ConvertToPersianString(0),
                    body = model.Body
                }));
            }
            return(Json(new { show = "false" }));
        }
예제 #2
0
        public virtual ActionResult DisLike(int id)
        {
            string result;
            int    likeCount = 0;

            if (!_commentService.IsUserLikeComment(id, User.Identity.Name))
            {
                likeCount = _commentService.DisLike(id, _userService.Find(User.Identity.Name));
                _uow.SaveChanges();
                result = "success";
            }
            else
            {
                result = "duplicate";
            }
            return(Json(new { result, count = ConvertToPersian.ConvertToPersianString(likeCount), commentId = id }));
        }
예제 #3
0
        public virtual ActionResult DisLike(int id)
        {
            string result    = "duplicate";
            int    likeCount = 0;

            //if (!_postService.IsUserLikePost(id, User.Identity.Name))
            //{
            //    likeCount = _postService.DisLike(id, _userService.Find(User.Identity.Name));
            //    _uow.SaveChanges();
            //    result = "success";
            //}
            //else
            //{
            //    result = "duplicate";
            //}
            return(Json(new { result, count = ConvertToPersian.ConvertToPersianString(likeCount) }));
        }
예제 #4
0
        public virtual ActionResult AddUserPostComment(AddUserCommentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(MVC.Comment.Views._AddUserPostComment, model));
            }
            var newComment = new Comment
            {
                AddedDate = DateAndTime.GetDateTime(),
                Body      = model.Body.ToSafeHtml(),
                LikeCount = 0
            };

            if (model.ReplyId != null)
            {
                newComment.Parent = _commentService.Find(model.ReplyId.Value);
            }

            newComment.User = _userService.Find(User.Identity.Name);

            bool sendData = newComment.IsApproved = !_optionService.ModeratingComment;

            newComment.Post = _postService.Find(model.Id);
            _commentService.AddComment(newComment);
            _uow.SaveChanges();


            if (model.ReplyId != null)
            {
                string toUserName;
                string toEmail;

                if (newComment.Parent.User != null)
                {
                    toUserName = newComment.Parent.User.UserName;
                    toEmail    = newComment.Parent.User.Email;
                }
                else
                {
                    toUserName = newComment.Parent.AnonymousUser.Name;
                    toEmail    = newComment.Parent.AnonymousUser.Email;
                }

                _emailService.SendCommentReplyNotification(new CommentReplyEmailNotificationData
                {
                    CommentId    = newComment.Id,
                    CommentText  = newComment.Body,
                    FromUserName = newComment.User.UserName,
                    PostId       = newComment.Post.Id,
                    PostTitle    = newComment.Post.Title,
                    ToUserName   = toUserName,
                    ToEmail      = toEmail
                }, CommentReplyType.ReplyToPostComment);
            }


            if (sendData)
            {
                return(Json(new
                {
                    show = "true",
                    name = User.Identity.Name,
                    date = DateAndTime.ConvertToPersian(DateAndTime.GetDateTime()),
                    likeCount = ConvertToPersian.ConvertToPersianString(0),
                    body = model.Body
                }));
            }
            return(Json(new { show = "false" }));
        }