public IActionResult BlogPostDetailsView(string id, [FromQuery] string version = null) { var user = _userContextAccessor.GetContext(); var blogPost = _blogManager.GetBlogPost(id, version); if (blogPost == null) { return(NotFound()); } // Ensure the user can edit the post if (!_blogSecurity.AuthorizeForEdit(blogPost)) { return(Unauthorized()); } var versionInfo = _blogManager.GetVersionInfo(blogPost.Id, version); ViewData["BlogVersionInfo"] = versionInfo; return(this.PartialContentView(new ContentBindings(versionInfo) { ViewPath = "~/UI/Views/Console/BlogPostDetails.cshtml", ViewModel = blogPost })); }
public IActionResult PublicView(string id, [FromQuery] string version = null, [FromQuery] bool preview = false) { var blogPost = _blogManager.GetBlogPost(id, version); if (blogPost.IsPrivate && !_blogSecurity.AuthorizeForRead(blogPost)) { return(Unauthorized()); } var settings = new ShellSettings(blogPost.Title); // show toolbar if user is authorized (unless in preview mode) preview = false; if (_blogSecurity.AuthorizeForEdit(blogPost) && !preview) { settings.Toolbar = new ToolbarSettings("~/UI/Views/Public/BlogPostToolbar.cshtml", blogPost); } var bindings = new ContentBindings { ContentType = BlogManager.CONTENT_TYPE_BLOGPOST, ContentId = blogPost.Id, VersionCode = blogPost.VersionCode, ViewPath = "~/UI/Views/Public/BlogPost.cshtml", ViewModel = blogPost, }; return(this.MasterPageView(bindings, settings)); }
public IActionResult UpdateBlogPost(BlogPostUpdateModel model) { if (model != null && ModelState.IsValid) { var user = _userContextAccessor.GetContext(); var oldPost = _blogManager.GetBlogPost(model.Id); if (_blogSecurity.AuthorizeForEdit(oldPost)) { var newPost = model.ProjectTo <BlogPost>(); newPost.UserId = user.UserId; // update the versioned post & non-versioned settings _blogManager.UpdateBlogPost(newPost); _blogManager.UpdateBlogPostSettings(newPost.Id, model.IsPrivate); // update category mappings var categoryIds = (model.CategoryIds ?? "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); _blogManager.SetBlogPostCategories(newPost.Id, categoryIds); // update version label if (!string.IsNullOrEmpty(model.NewVersionLabel)) { _contentManager.UpdateVersionLabel(BlogManager.CONTENT_TYPE_BLOGPOST, model.Id, model.VersionCode, model.NewVersionLabel).Wait(); } } if (model.ShouldPublish && _blogSecurity.AuthorizeForPublish(oldPost)) { _blogManager.PublishBlogPost(model.Id, model.VersionCode); } return(Ok(model)); } return(BadRequest(ModelState)); }