Esempio n. 1
0
        public IActionResult BlogPostCreateForm()
        {
            if (!_blogSecurity.AuthorizeForCreate())
            {
                return(Unauthorized());
            }

            var userContext = _userContextAccessor.GetContext();
            var blogPost    = _blogManager.CreateBlogPost(userContext.UserId);
            var versionInfo = _contentManager.GetVersionInfo(BlogManager.CONTENT_TYPE_BLOGPOST, blogPost.Id, blogPost.VersionCode).Result;

            // build the view model
            var blogPostViewModel = blogPost.ProjectTo <BlogPostViewModel>();

            blogPostViewModel.VersionLabel      = versionInfo.VersionLabel;
            blogPostViewModel.PostPrivacyConfig = BuildPostPrivacyOptions(blogPost);
            blogPostViewModel.Categories        = new BlogCategory[] { };

            return(this.PartialContentView(new ContentBindings(versionInfo)
            {
                ViewPath = "/UI/Views/Console/BlogPostDesign.cshtml",
                ViewModel = blogPostViewModel,
                Editable = true
            }));
        }
Esempio n. 2
0
        public ActionResult Create(CreateBlogViewModels model)
        {
            if (!ModelState.IsValid || !IsFileValid(model.BlogImage))
            {
                return(View());
            }

            var manager      = new BlogManager();
            var uploadedFile = GetFile(model.BlogImage);

            manager.CreateBlogPost(model.Title, model.Post, model.BlogImage.FileName, uploadedFile, model.Tags, HttpContext.User.Identity.Name);

            return(RedirectToAction("Index"));
        }