示例#1
0
        public ActionResult SubmitEdit(EditPostPageViewModel currentPage)
        {
            //make sure we can do it
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Admin"));
            }

            if (ModelState.IsValid)
            {
                //get the original from file with markdown for image parsing
                var originalPost = StorageHelper.ReadPost(currentPage.PostedTime.Year, currentPage.Slug, true);

                if (originalPost != null)
                {
                    //first we delete abandoned images
                    PostHelper.ProcessRemovedImages(originalPost.BodyMarkdown, currentPage.BodyMarkdown);

                    //NOTICE the html markdown switcharoo
                    //update with the fields we allow changing
                    originalPost.BodyHtml      = CommonMarkConverter.Convert(currentPage.BodyMarkdown);
                    originalPost.BodyMarkdown  = currentPage.BodyMarkdown;
                    originalPost.DontIndexPost = currentPage.DontIndexPost;
                    originalPost.MetaDescPost  = currentPage.MetaDescPost;
                    originalPost.Title         = currentPage.Title;
                    originalPost.Categories    = currentPage.Categories;

                    //PS get the new read time after the new body has been populated
                    originalPost.ReadTime = PostHelper.GetReadTime(ref originalPost);

                    //save the post (will update the cache as well)
                    StorageHelper.SavePost(originalPost);

                    return(RedirectToAction("Index", "Post", new { year = originalPost.PostedTime.Year, slug = originalPost.Slug }));
                }
            }

            //not valid, return
            return(View("Edit", currentPage));
        }
示例#2
0
        public ActionResult Submit(SubmitPageViewModel currentPage)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Admin"));
            }

            if (ModelState.IsValid)
            {
                var now  = DateTime.Now;
                var slug = SlugHelper.CreateSlug(now.Year, currentPage.Slug);

                //validate the slug, null means slug exists
                if (string.IsNullOrWhiteSpace(slug))
                {
                    ModelState.AddModelError("Slug", "The slug is already in use.");
                    currentPage.Slug = string.Empty;
                    return(View("Submit", currentPage));
                }

                StorageHelper.SavePost(new Post
                {
                    BodyHtml      = CommonMarkConverter.Convert(currentPage.BodyText),
                    BodyMarkdown  = currentPage.BodyText,
                    DontIndexPost = currentPage.DontIndexNewPost,
                    MetaDescPost  = currentPage.MetaDescNewPost,
                    PostedTime    = now,
                    Slug          = slug,
                    Title         = currentPage.Title,
                    ReadTime      = PostHelper.GetReadTime(currentPage.BodyText),
                    Categories    = currentPage.Categories
                });

                return(RedirectToAction("Index", "Post", new { year = now.Year, slug }));
            }

            //not valid
            return(View("Submit", currentPage));
        }