Пример #1
0
        public async Task <IActionResult> UpdatePost(Post post)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", post));
            }

            var existing = await this.blog.GetPostById(post.Id) ?? post;

            string categories = Request.Form["categories"];

            existing.Categories = categories.Split(",", StringSplitOptions.RemoveEmptyEntries)
                                  .Select(c => c.Trim().ToLowerInvariant()).ToList();
            existing.Title = post.Title.Trim();
            existing.Slug  = post.Slug.Trim();
            existing.Slug  = !string.IsNullOrWhiteSpace(post.Slug)
                ? post.Slug.Trim()
                : Models.Post.CreateSlug(post.Title);
            existing.IsPublished = post.IsPublished;
            existing.Content     = post.Content.Trim();
            existing.Excerpt     = post.Excerpt.Trim();

            await this.blog.SavePost(existing);

            await SaveFilesToDisk(existing);

            return(Redirect(post.GetLink()));
        }
Пример #2
0
        private Post ToMetaWebLogPost(Models.Post post)
        {
            var request = this.context.HttpContext.Request;
            var url     = request.Scheme + "://" + request.Host;

            return(new Post
            {
                postid = post.Id,
                title = post.Title,
                wp_slug = post.Slug,
                permalink = url + post.GetLink(),
                dateCreated = post.PubDate,
                description = post.Content,
                categories = post.Categories.ToArray()
            });
        }