Ejemplo n.º 1
0
        public bool CreateCommentFromPost(int contentId, DisqusPost post)
        {
            var posts   = this.services.ContentManager.Query <DisqusPostMappingPart, DisqusPostMappingRecord>().Where(p => p.PostId == post.Id);
            var success = false;

            if (posts.Count() == 0)
            {
                var ctx = new CreateCommentContext()
                {
                    Author      = post.Author.Name,
                    CommentText = post.Message,
                    CommentedOn = contentId,
                    Email       = post.Author.Email,
                    SiteName    = post.Author.Url,
                };

                var commentPart = this.commentService.CreateComment(ctx, false);

                commentPart.Record.CommentDateUtc = post.CreatedAt;
                commentPart.Record.Status         = CommentStatus.Approved;

                this.postMappingRepository.Create(new DisqusPostMappingRecord {
                    PostId = post.Id, ContentItemRecord = commentPart.ContentItem.Record
                });
                success = true;
            }

            return(success);
        }
Ejemplo n.º 2
0
        public bool CreateCommentFromPost(int contentId, DisqusPost post)
        {
            var posts = _orchardServices.ContentManager
                        .Query <DisqusPostMappingPart, DisqusPostMappingRecord>()
                        .Where(p => p.PostId == post.Id);

            if (posts.Count() > 0)
            {
                return(false);
            }

            var context = new CreateCommentContext
            {
                Author      = post.Author.Name,
                CommentText = post.Message,
                CommentedOn = contentId,
                Email       = post.Author.Email,
                SiteName    = post.Author.Url,
            };

            var commentPart = _commentService.CreateComment(context, false);

            commentPart.Record.CommentDateUtc = post.CreatedAt;
            commentPart.Record.Status         = CommentStatus.Approved;

            var record = new DisqusPostMappingRecord {
                PostId = post.Id, ContentItemRecord = commentPart.ContentItem.Record
            };

            _postMappingRepository.Create(record);

            return(true);
        }
Ejemplo n.º 3
0
        public ActionResult Create(string returnUrl)
        {
            if (!Services.Authorizer.Authorize(Permissions.AddComment, T("Couldn't add comment")))
            {
                return(this.RedirectLocal(returnUrl, "~/"));
            }

            var viewModel = new CommentsCreateViewModel();

            TryUpdateModel(viewModel);

            var context = new CreateCommentContext {
                Author      = viewModel.Name,
                CommentText = viewModel.CommentText,
                Email       = viewModel.Email,
                SiteName    = viewModel.SiteName,
                CommentedOn = viewModel.CommentedOn
            };


            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(context.SiteName) && !context.SiteName.StartsWith("http://") && !context.SiteName.StartsWith("https://"))
                {
                    context.SiteName = "http://" + context.SiteName;
                }

                CommentPart commentPart = _commentService.CreateComment(context, Services.WorkContext.CurrentSite.As <CommentSettingsPart>().Record.ModerateComments);

                if (commentPart.Record.Status == CommentStatus.Pending)
                {
                    // if the user who submitted the comment has the right to moderate, don't make this comment moderated
                    if (Services.Authorizer.Authorize(Permissions.ManageComments))
                    {
                        commentPart.Record.Status = CommentStatus.Approved;
                    }
                    else
                    {
                        Services.Notifier.Information(T("Your comment will appear after the site administrator approves it."));
                    }
                }
            }
            else
            {
                foreach (var error in ModelState.Values.SelectMany(m => m.Errors).Select(e => e.ErrorMessage))
                {
                    _notifier.Error(T(error));
                }
            }

            if (!ModelState.IsValid)
            {
                TempData["CreateCommentContext.Name"]        = context.Author;
                TempData["CreateCommentContext.CommentText"] = context.CommentText;
                TempData["CreateCommentContext.Email"]       = context.Email;
                TempData["CreateCommentContext.SiteName"]    = context.SiteName;
            }

            return(this.RedirectLocal(returnUrl, "~/"));
        }