public CommentPart CreateComment(CreateCommentContext context, bool moderateComments)
        {
            var comment = _orchardServices.ContentManager.Create<CommentPart>("Comment");

            comment.Record.Author = context.Author;
            comment.Record.CommentDateUtc = _clock.UtcNow;
            comment.Record.CommentText = context.CommentText;
            comment.Record.Email = context.Email;
            comment.Record.SiteName = context.SiteName;
            comment.Record.UserName = (_orchardServices.WorkContext.CurrentUser != null ? _orchardServices.WorkContext.CurrentUser.UserName : null);
            comment.Record.CommentedOn = context.CommentedOn;

            comment.Record.Status = _commentValidator.ValidateComment(comment)
                ? moderateComments ? CommentStatus.Pending : CommentStatus.Approved
                : CommentStatus.Spam;

            // store id of the next layer for large-grained operations, e.g. rss on blog
            //TODO:(rpaquay) Get rid of this (comment aspect takes care of container)
            var commentedOn = _orchardServices.ContentManager.Get<ICommonPart>(comment.Record.CommentedOn);
            if (commentedOn != null && commentedOn.Container != null) {
                comment.Record.CommentedOnContainer = commentedOn.Container.ContentItem.Id;
            }

            return comment;
        }
Example #2
0
        public CommentPart CreateComment(CreateCommentContext context, bool moderateComments)
        {
            var comment = _orchardServices.ContentManager.Create <CommentPart>("Comment");

            comment.Record.Author         = context.Author;
            comment.Record.CommentDateUtc = _clock.UtcNow;
            comment.Record.CommentText    = context.CommentText;
            comment.Record.Email          = context.Email;
            comment.Record.SiteName       = context.SiteName;
            comment.Record.UserName       = (_orchardServices.WorkContext.CurrentUser != null ? _orchardServices.WorkContext.CurrentUser.UserName : null);
            comment.Record.CommentedOn    = context.CommentedOn;

            comment.Record.Status = _commentValidator.ValidateComment(comment)
                ? moderateComments ? CommentStatus.Pending : CommentStatus.Approved
                : CommentStatus.Spam;

            // store id of the next layer for large-grained operations, e.g. rss on blog
            //TODO:(rpaquay) Get rid of this (comment aspect takes care of container)
            var commentedOn = _orchardServices.ContentManager.Get <ICommonPart>(comment.Record.CommentedOn);

            if (commentedOn != null && commentedOn.Container != null)
            {
                comment.Record.CommentedOnContainer = commentedOn.Container.ContentItem.Id;
            }

            return(comment);
        }
        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;
        }
Example #4
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);

            if (!ModelState.IsValidField("Name")) {
                Services.Notifier.Error(T("Name is mandatory and must have less than 255 chars"));
            }

            if (!ModelState.IsValidField("Email")) {
                Services.Notifier.Error(T("Email is invalid or is longer than 255 chars"));
            }

            if (!ModelState.IsValidField("Site")) {
                Services.Notifier.Error(T("Site url is invalid or is longer than 255 chars"));
            }

            if (!ModelState.IsValidField("CommentText")) {
                Services.Notifier.Error(T("Comment is mandatory"));
            }
            
            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 {
                TempData["CreateCommentContext.Name"] = context.Author;
                TempData["CreateCommentContext.CommentText"] = context.CommentText;
                TempData["CreateCommentContext.Email"] = context.Email;
                TempData["CreateCommentContext.SiteName"] = context.SiteName;
            }

            return this.RedirectLocal(returnUrl, "~/");
        }
Example #5
0
 public CommentPart CreateComment(CreateCommentContext context, bool moderateComments) {
     return _orchardServices.ContentManager.Create<CommentPart>("Comment", comment => {
         comment.Record.Author = context.Author;
         comment.Record.CommentDateUtc = _clock.UtcNow;
         comment.Record.CommentText = context.CommentText;
         comment.Record.Email = context.Email;
         comment.Record.SiteName = context.SiteName;
         comment.Record.UserName = (_orchardServices.WorkContext.CurrentUser != null ? _orchardServices.WorkContext.CurrentUser.UserName : null);
         comment.Record.CommentedOn = context.CommentedOn;
         comment.Record.Status = _commentValidator.ValidateComment(comment)
                                     ? moderateComments ? CommentStatus.Pending : CommentStatus.Approved
                                     : CommentStatus.Spam;
         var commentedOn = _orchardServices.ContentManager.Get<ICommonPart>(comment.Record.CommentedOn);
         if (commentedOn != null && commentedOn.Container != null) {
             comment.Record.CommentedOnContainer = commentedOn.Container.ContentItem.Id;
         }
     });
 }
        public ActionResult Create(string returnUrl) {
            if (!Services.Authorizer.Authorize(Permissions.AddComment, T("Couldn't add comment")))
                return !String.IsNullOrEmpty(returnUrl)
                    ? Redirect(returnUrl)
                    : Redirect("~/");
            
            var viewModel = new CommentsCreateViewModel();
            try {

                // UpdateModel(viewModel);

                if(!TryUpdateModel(viewModel)) {
                    if (Request.Form["Name"].IsNullOrEmptyTrimmed()) {
                        _notifier.Error("You must provide a Name in order to comment");
                    }
                    return Redirect(returnUrl);
                }

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

                Comment comment = _commentService.CreateComment(context, CurrentSite.As<CommentSettings>().Record.ModerateComments);

                if (comment.Record.Status == CommentStatus.Pending)
                    Services.Notifier.Information(T("Your comment will appear after the site administrator approves it."));

                return !String.IsNullOrEmpty(returnUrl)
                    ? Redirect(returnUrl)
                    : Redirect("~/");
            }
            catch (Exception exception) {
                _notifier.Error(T("Creating Comment failed: " + exception.Message));
                // return View(viewModel);
                return Redirect(returnUrl);
            }
        }
 public CommentPart CreateComment(CreateCommentContext context, bool moderateComments)
 {
     return(_orchardServices.ContentManager.Create <CommentPart>("Comment", comment => {
         comment.Record.Author = context.Author;
         comment.Record.CommentDateUtc = _clock.UtcNow;
         comment.Record.CommentText = context.CommentText;
         comment.Record.Email = context.Email;
         comment.Record.SiteName = context.SiteName;
         comment.Record.UserName = (_orchardServices.WorkContext.CurrentUser != null ? _orchardServices.WorkContext.CurrentUser.UserName : null);
         comment.Record.CommentedOn = context.CommentedOn;
         comment.Record.Status = _commentValidator.ValidateComment(comment)
                                     ? moderateComments ? CommentStatus.Pending : CommentStatus.Approved
                                     : CommentStatus.Spam;
         var commentedOn = _orchardServices.ContentManager.Get <ICommonPart>(comment.Record.CommentedOn);
         if (commentedOn != null && commentedOn.Container != null)
         {
             comment.Record.CommentedOnContainer = commentedOn.Container.ContentItem.Id;
         }
         commentedOn.As <CommentsPart>().Record.CommentPartRecords.Add(comment.Record);
     }));
 }
Example #8
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;
        }