Esempio n. 1
0
        public IActionResult BlogPostEditForm(string id, [FromQuery] string version = null)
        {
            var user     = _userContextAccessor.GetContext();
            var blogPost = _blogManager.GetBlogPost(id, version);

            // Ensure the user can edit the post
            if (!_blogSecurity.AuthorizeForEdit(blogPost))
            {
                return(Unauthorized());
            }

            // If the version specified is not already a draft, then create a new draft version
            if (blogPost.Status != Connect.Models.ContentStatus.Draft)
            {
                blogPost = _blogManager.CloneBlogPostAsDraft(blogPost, user.UserId);
            }

            // Create the view model
            var blogPostViewModel = blogPost.ProjectTo <BlogPostViewModel>();
            var versionInfo       = _contentManager.GetVersionInfo(BlogManager.CONTENT_TYPE_BLOGPOST, blogPost.Id, blogPost.VersionCode).Result;

            blogPostViewModel.VersionLabel      = versionInfo.VersionLabel;
            blogPostViewModel.PostPrivacyConfig = BuildPostPrivacyOptions(blogPost);
            blogPostViewModel.Categories        = blogPost.Categories.Select(x => x.Category);


            return(this.PartialContentView(new ContentBindings(versionInfo)
            {
                ViewPath = "/UI/Views/Console/BlogPostDesign.cshtml",
                ViewModel = blogPostViewModel,
                Editable = true
            }));
        }