public ActionResult Create(int forumId) { var forumPart = _forumService.Get(forumId, VersionOptions.Latest); if (forumPart == null) { return(HttpNotFound()); } var thread = _orchardServices.ContentManager.New <ThreadPart>(forumPart.ThreadType); thread.ForumPart = forumPart; if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.PublishContent, thread, T("Not allowed to create thread"))) { return(new HttpUnauthorizedResult()); } var post = _orchardServices.ContentManager.New <PostPart>(forumPart.PostType); post.ThreadPart = thread; var threadModel = _orchardServices.ContentManager.BuildEditor(thread); var postModel = _orchardServices.ContentManager.BuildEditor(post); DynamicZoneExtensions.RemoveItemFrom(threadModel.Sidebar, "Content_SaveButton"); var viewModel = Shape.ViewModel() .Thread(threadModel) .Post(postModel); return(View((object)viewModel)); }
public ActionResult CreatePOST(int forumId) { var forumPart = _forumService.Get(forumId, VersionOptions.Latest); if (forumPart == null) { return(HttpNotFound()); } var thread = _orchardServices.ContentManager.Create <ThreadPart>(forumPart.ThreadType, VersionOptions.Draft, o => { o.ForumPart = forumPart; }); if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.PublishContent, thread, T("Not allowed to create thread"))) { return(new HttpUnauthorizedResult()); } var threadModel = _orchardServices.ContentManager.UpdateEditor(thread, this); var post = _orchardServices.ContentManager.Create <PostPart>(forumPart.PostType, VersionOptions.Draft, o => { o.ThreadPart = thread; }); if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.PublishContent, post, T("Not allowed to create post"))) { return(new HttpUnauthorizedResult()); } var postModel = _orchardServices.ContentManager.UpdateEditor(post, this); post.ThreadPart = thread; if (!ModelState.IsValid) { _orchardServices.TransactionManager.Cancel(); DynamicZoneExtensions.RemoveItemFrom(threadModel.Sidebar, "Content_SaveButton"); var viewModel = Shape.ViewModel() .Thread(threadModel) .Post(postModel); return(View((object)viewModel)); } _orchardServices.ContentManager.Publish(thread.ContentItem); _orchardServices.ContentManager.Publish(post.ContentItem); _orchardServices.Notifier.Information(T("Your {0} has been created.", thread.TypeDefinition.DisplayName)); return(Redirect(Url.ThreadView(thread))); }