Esempio n. 1
0
        public ActionResult CreatePOST(int contentId)
        {
            var contentItem = _orchardServices.ContentManager.Get(contentId, VersionOptions.Latest);

            bool isPost   = contentItem.Has <PostPart>();
            bool isThread = contentItem.Has <ThreadPart>();

            if (!isPost && !isThread)
            {
                return(HttpNotFound());
            }

            var forumPart  = HierarchyHelpers.GetForum(contentItem);
            var post       = _orchardServices.ContentManager.New <PostPart>(forumPart.PostType);
            var threadPart = HierarchyHelpers.GetThreadPart(contentItem);

            post.ThreadPart = threadPart;

            if (isThread)
            {
                // Attach to parent post and NOT to the thread
                post.RepliedOn = contentItem.As <ThreadPart>().FirstPost.Id;
            }
            else
            {
                post.RepliedOn = contentItem.As <PostPart>().Id;
            }

            if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.PublishContent, post, T("Not allowed to create post")))
            {
                return(new HttpUnauthorizedResult());
            }

            _orchardServices.ContentManager.Create(post.ContentItem);
            var model = _orchardServices.ContentManager.UpdateEditor(post, this);

            if (!ModelState.IsValid)
            {
                _orchardServices.TransactionManager.Cancel();
                return(View((object)model));
            }

            _orchardServices.ContentManager.Publish(post.ContentItem);

            _orchardServices.Notifier.Information(T("Your {0} has been created.", post.TypeDefinition.DisplayName));

            var pager = new ThreadPager(_orchardServices.WorkContext.CurrentSite, post.ThreadPart.PostCount);

            return(Redirect(Url.PostView(post, pager)));
        }
Esempio n. 2
0
        public ActionResult Delete(int contentId)
        {
            var contentItem = _orchardServices.ContentManager.Get(contentId);

            var thread = contentItem.As <ThreadPart>();

            if (thread != null)
            {
                if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.DeleteContent, contentItem, T("Not allowed to delete thread")))
                {
                    return(new HttpUnauthorizedResult());
                }

                _orchardServices.ContentManager.Remove(contentItem);
                _orchardServices.Notifier.Information(T("Thread has been deleted."));
                return(Redirect(Url.ForumView(thread.ForumPart)));
            }

            var post = contentItem.As <PostPart>();

            if (post != null)
            {
                if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.DeleteContent, contentItem, T("Not allowed to delete post")))
                {
                    return(new HttpUnauthorizedResult());
                }

                if (post.IsParentThread())
                {
                    _orchardServices.ContentManager.Remove(post.ThreadPart.ContentItem);
                    _orchardServices.Notifier.Information(T("Thread has been deleted."));
                    return(Redirect(Url.ForumView(post.ThreadPart.ForumPart)));
                }
                else
                {
                    _orchardServices.ContentManager.Remove(contentItem);
                    _orchardServices.Notifier.Information(T("Post has been deleted."));

                    var pager = new ThreadPager(_orchardServices.WorkContext.CurrentSite, post.ThreadPart.PostCount);
                    return(Redirect(Url.ThreadView(post.ThreadPart, pager)));
                }
            }

            return(Redirect(Url.Forums()));
        }
Esempio n. 3
0
        protected override DriverResult Display(ThreadPart part, string displayType, dynamic shapeHelper)
        {
            var results = new List <DriverResult>();

            if (displayType.Equals("SummaryAdmin", StringComparison.OrdinalIgnoreCase))
            {
                results.Add(ContentShape("Parts_Threads_Thread_SummaryAdmin",
                                         () => shapeHelper.Parts_Threads_Thread_SummaryAdmin()));
                results.Add(ContentShape("Parts_Threads_Thread_Metadata_SummaryAdmin",
                                         () => shapeHelper.Parts_Threads_Thread_Metadata_SummaryAdmin()));
            }

            if (part.IsClosed)
            {
                results.Add(ContentShape("Parts_Threads_Thread_Closed",
                                         () => shapeHelper.Parts_Threads_Thread_Closed()));
            }

            results.AddRange(new [] {
                ContentShape("Parts_Threads_Thread_ThreadReplyCount",
                             () => shapeHelper.Parts_Threads_Thread_ThreadReplyCount(ReplyCount: part.ReplyCount)),
                ContentShape("Parts_Thread_Manage", () => {
                    var newPost        = _contentManager.New <PostPart>(part.FirstPost.ContentItem.ContentType);
                    newPost.ThreadPart = part;
                    return(shapeHelper.Parts_Thread_Manage(FirstPost: part.FirstPost, NewPost: newPost));
                }),
                ContentShape("Forum_Metadata_First", () => shapeHelper.Forum_Metadata_First(Post: part.FirstPost)),
                ContentShape("Forum_Metadata_Latest", () => {
                    var post  = part.LatestPost;
                    var pager = new ThreadPager(_workContextAccessor.GetContext().CurrentSite, part.PostCount);
                    return(shapeHelper.Forum_Metadata_Latest(Post: post, Pager: pager));
                }),
                ContentShape("Parts_Thread_Posts_Users", () => {
                    var users = _postService.GetUsersPosted(part);
                    return(shapeHelper.Parts_Thread_Posts_Users(Users: users));
                })
            });

            return(Combined(results.ToArray()));
        }
Esempio n. 4
0
 protected override DriverResult Display(PostPart part, string displayType, dynamic shapeHelper)
 {
     return(Combined(
                ContentShape("Parts_Threads_Post_Body",
                             () => {
         var bodyText = _htmlFilters.Aggregate(part.Text, (text, filter) => filter.ProcessContent(text, GetFlavor(part)));
         return shapeHelper.Parts_Threads_Post_Body(Html: new HtmlString(bodyText));
     }),
                ContentShape("Parts_Threads_Post_Body_Summary",
                             () => {
         var pager = new ThreadPager(_workContextAccessor.GetContext().CurrentSite, part.ThreadPart.PostCount);
         var bodyText = _htmlFilters.Aggregate(part.Text, (text, filter) => filter.ProcessContent(text, GetFlavor(part)));
         return shapeHelper.Parts_Threads_Post_Body_Summary(Html: new HtmlString(bodyText), Pager: pager);
     }),
                ContentShape("Parts_Post_Manage", () => {
         var newPost = _contentManager.New <PostPart>(part.ContentItem.ContentType);
         newPost.ThreadPart = part.ThreadPart;
         return shapeHelper.Parts_Post_Manage(ContentPart: part, NewPost: newPost);
     }),
                ContentShape("Parts_Thread_Post_Metadata_SummaryAdmin", () =>
                             shapeHelper.Parts_Thread_Post_Metadata_SummaryAdmin(ContentPart: part))
                ));
 }