コード例 #1
0
ファイル: CommentController.cs プロジェクト: saeidmh83/MyCMS
        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 static MvcHtmlString ConvertToPersianDateTime(this HtmlHelper htmlHelper, DateTime dateTime,
                                                      string mode = "")
 {
     return(dateTime.Year == 1 ? null : MvcHtmlString.Create(DateAndTime.ConvertToPersian(dateTime, mode)));
 }
コード例 #3
0
ファイル: CommentController.cs プロジェクト: saeidmh83/MyCMS
        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" }));
        }