Exemplo n.º 1
0
        private Post ToMetaWeblogPost(Core.Post post)
        {
            if (!post.IsPublished)
            {
                return(null);
            }
            var pubDate = post.PubDateUtc.GetValueOrDefault();
            var link    = $"/post/{pubDate.Year}/{pubDate.Month}/{pubDate.Day}/{post.Slug.Trim().ToLower()}";

            var mPost = new Post
            {
                postid      = post.Id,
                categories  = post.Categories.Select(p => p.DisplayName).ToArray(),
                dateCreated = _dateTimeResolver.ToTimeZone(post.CreateTimeUtc),
                description = post.ContentAbstract,
                link        = link,
                permalink   = $"{Helper.ResolveRootUrl(null, _blogConfig.GeneralSettings.CanonicalPrefix, true)}/{link}",
                title       = post.Title,
                wp_slug     = post.Slug,
                mt_keywords = string.Join(',', post.Tags.Select(p => p.DisplayName)),
                mt_excerpt  = post.ContentAbstract,
                userid      = _blogConfig.GeneralSettings.OwnerName
            };

            return(mPost);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(Guid id)
        {
            var post = await _postService.GetAsync(id);

            if (null == post)
            {
                return(NotFound());
            }

            var viewModel = new PostEditViewModel
            {
                PostId              = post.Id,
                IsPublished         = post.IsPublished,
                EditorContent       = post.RawPostContent,
                Slug                = post.Slug,
                Title               = post.Title,
                EnableComment       = post.CommentEnabled,
                ExposedToSiteMap    = post.ExposedToSiteMap,
                FeedIncluded        = post.IsFeedIncluded,
                ContentLanguageCode = post.ContentLanguageCode
            };

            if (post.PubDateUtc is not null)
            {
                viewModel.PublishDate = _dateTimeResolver.ToTimeZone(post.PubDateUtc.GetValueOrDefault());
            }

            var tagStr = post.Tags
                         .Select(p => p.DisplayName)
                         .Aggregate(string.Empty, (current, item) => current + item + ",");

            tagStr         = tagStr.TrimEnd(',');
            viewModel.Tags = tagStr;

            var cats = await _categoryService.GetAllAsync();

            if (cats.Count > 0)
            {
                var cbCatList = cats.Select(p =>
                                            new CheckBoxViewModel(
                                                p.DisplayName,
                                                p.Id.ToString(),
                                                post.Categories.Any(q => q.Id == p.Id)));
                viewModel.CategoryList = cbCatList;
            }

            return(View("CreateOrEdit", viewModel));
        }