Esempio n. 1
0
        public ActionResult CreateWithQuote(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 part      = _orchardServices.ContentManager.New <PostPart>(forumPart.PostType);

            part.ThreadPart = HierarchyHelpers.GetThreadPart(contentItem);

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

            part.Text = string.Format("<blockquote>{0}</blockquote>{1}", contentItem.As <PostPart>().Text, Environment.NewLine);

            var model = _orchardServices.ContentManager.BuildEditor(part);

            return(View("Create", (object)model));
        }
Esempio n. 2
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)));
        }