Exemplo n.º 1
0
        public bool EditPost(string postid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUser(username, password);

            var existing = _blog.GetPostById(postid).GetAwaiter().GetResult();

            if (existing != null)
            {
                existing.Title       = post.title;
                existing.Slug        = post.wp_slug;
                existing.Content     = post.description;
                existing.IsPublished = publish;
                existing.Categories  = post.categories;

                if (post.dateCreated != DateTime.MinValue)
                {
                    existing.PubDate = post.dateCreated;
                }

                _blog.SavePost(existing).GetAwaiter().GetResult();

                return(true);
            }

            return(false);
        }
        public string AddPost(string blogid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUser(username, password);

            var newPost = new Models.Post
            {
                Title = post.title,
                //Done:假如mt_excerpt為null,取文章前N個字
                Excerpt= string.IsNullOrWhiteSpace(post.mt_excerpt)? HtmlHelper.HtmlInnerText(post.description): post.mt_excerpt,
                Content = post.description,
                IsPublished = publish,
                Categories = post.categories
            };
            //TODO:做成可選擇GUID/時間格式/Title模式
            newPost.Slug = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : newPost.ID;//(Models.Post.CreateSlug(post.title))

            if (post.dateCreated != DateTime.MinValue)
            {
                newPost.PubDate = post.dateCreated.ToUniversalTime();
            }

            _blog.SavePost(newPost).GetAwaiter().GetResult();

            return newPost.ID;
        }
        public string AddPost(string blogid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUser(username, password);

            var newPost = new Models.Post
            {
                Title          = post.title,
                Slug           = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : Models.Post.CreateSlug(post.title),
                Content        = post.description,
                IsPublished    = publish,
                PostCategories = post.categories.Select(c => new PostCategory {
                    Category = new Category {
                        Name = c.ToLower()
                    }
                }).ToList()
            };

            if (post.dateCreated != DateTime.MinValue)
            {
                newPost.PubDate = post.dateCreated;
            }

            _blog.SavePost(newPost).GetAwaiter().GetResult();

            return(newPost.Id);
        }
        public bool EditPost(string postid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUser(username, password);

            var existing = _blog.GetPostById(postid).GetAwaiter().GetResult();

            if (existing != null)
            {
                existing.Title = post.title;
                existing.Slug = post.wp_slug!=null? post.wp_slug : existing.Slug;
                existing.Content = post.description;
                existing.IsPublished = publish;
                existing.Categories = post.categories;
                //DONE:假如mt_excerpt為null,取文章前N個字
                existing.Excerpt = string.IsNullOrWhiteSpace(post.mt_excerpt) ? HtmlHelper.HtmlInnerText(post.description) : post.mt_excerpt;

                if (post.dateCreated != DateTime.MinValue)
                {
                    //如果日期超過,以現在為準
                    if(post.dateCreated.ToUniversalTime()>DateTime.UtcNow)
                        existing.PubDate = DateTime.UtcNow;
                    else
                        existing.PubDate = post.dateCreated;
                }

                _blog.SavePost(existing).GetAwaiter().GetResult();

                return true;
            }

            return false;
        }
Exemplo n.º 5
0
    private Post ToMetaWeblogPost(Core.PostFeature.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 = _timeZoneResolver.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.º 6
0
        /// <summary>
        ///     The AddPost
        /// </summary>
        /// <param name="blogId">The blogId<see cref="string" /></param>
        /// <param name="userId">The userId<see cref="string" /></param>
        /// <param name="password">The password<see cref="string" /></param>
        /// <param name="post">The post<see cref="Post" /></param>
        /// <param name="publish">The publish<see cref="bool" /></param>
        /// <returns>The <see cref="string" /></returns>
        public string AddPost(
            string blogId,
            string userId,
            string password,
            Post post,
            bool publish)
        {
            ValidateUser(userId, password);

            var newPost = new Models.Post
            {
                Title       = post.title,
                Slug        = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : PostBase.CreateSlug(post.title),
                Content     = post.description,
                IsPublished = publish,
                Categories  = post.categories
            };

            if (post.dateCreated != DateTime.MinValue)
            {
                newPost.PubDate = post.dateCreated;
            }

            _blog.SavePost(newPost)
            .GetAwaiter()
            .GetResult();

            return(newPost.Id);
        }
Exemplo n.º 7
0
        /// <summary>
        ///     The EditPostAsync
        /// </summary>
        /// <param name="postId">The postId<see cref="string" /></param>
        /// <param name="userId">The userId<see cref="string" /></param>
        /// <param name="password">The password<see cref="string" /></param>
        /// <param name="post">The post<see cref="Post" /></param>
        /// <param name="publish">The publish<see cref="bool" /></param>
        /// <returns>
        ///     The
        ///     <see>
        ///         <cref>Task{bool}</cref>
        ///     </see>
        /// </returns>
        public async Task <bool> EditPostAsync(
            string postId,
            string userId,
            string password,
            Post post,
            bool publish)
        {
            ValidateUser(userId, password);

            Models.Post existing = await _blog.GetPostById(postId);

            if (existing == null)
            {
                return(false);
            }

            existing.Title       = post.title;
            existing.Slug        = post.wp_slug;
            existing.Content     = post.description;
            existing.IsPublished = publish;
            existing.Categories  = post.categories;

            if (post.dateCreated != DateTime.MinValue)
            {
                existing.PubDate = post.dateCreated;
            }

            await _blog.SavePost(existing);

            return(true);
        }
        public string AddPost(string blogid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUser(username, password);

            var newPost = PostModule.Create(post.title, Microsoft.FSharp.Core.OptionModule.OfObj(post.wp_slug), string.Empty, post.description, publish);

            newPost = PostModule.WithCategories(String.Join(",", post.categories), newPost);

            if (post.dateCreated != DateTime.MinValue)
            {
                newPost = PostModule.WithPubDate(post.dateCreated, newPost);
            }

            _blog.SavePost(newPost).GetAwaiter().GetResult();

            return(newPost.ID);
        }
        public string AddPost(string blogid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUserAsync(username, password).GetAwaiter().GetResult();

            var newPost = new Models.Post
            {
                Title      = post.title,
                Slug       = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : post.title.GenerateSlug(),
                Content    = post.description,
                Status     = publish?Status.Publish:Status.Draft,
                Categories = post.categories
            };

            if (post.dateCreated != DateTime.MinValue)
            {
                newPost.PubDate = post.dateCreated;
            }

            return(_blog.SavePost(newPost).GetAwaiter().GetResult());
        }
Exemplo n.º 10
0
        public string AddPage(string blogid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUser(username, password);

            var newPage = new Models.Page
            {
                Title       = post.title,
                Slug        = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : Models.Post.CreateSlug(post.title),
                Content     = post.description,
                IsPublished = publish
            };

            if (post.dateCreated != DateTime.MinValue)
            {
                newPage.PubDate = post.dateCreated;
            }

            _page.SavePage(newPage).GetAwaiter().GetResult();

            return(newPage.ID);
        }
Exemplo n.º 11
0
        public string AddPost(string blogid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUser(username, password);

            var newPost = new Data.Entities.Post
            {
                Title       = post.title,
                Slug        = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : Data.Entities.Post.CreateSlug(post.title),
                Content     = post.description,
                IsPublished = publish,
                Categories  = post.categories
            };

            if (post.dateCreated != DateTime.MinValue)
            {
                newPost.PubDate = post.dateCreated;
            }

            _blog.SavePost(newPost).GetAwaiter().GetResult();

            return(newPost.ID);
        }
        public bool EditPost(string postid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUser(username, password);

            var existing = _blog.GetPostById(postid).GetAwaiter().GetResult();

            if (existing != null)
            {
                var update = PostModule.Create(post.title, Microsoft.FSharp.Core.OptionModule.OfObj(post.wp_slug), existing.Excerpt, post.description, existing.IsPublished);
                existing = PostModule.UpdateWith(existing, update);
                existing = PostModule.WithCategories(String.Join(",", post.categories), existing);

                if (post.dateCreated != DateTime.MinValue)
                {
                    existing = PostModule.WithPubDate(post.dateCreated, existing);
                }

                _blog.SavePost(existing).GetAwaiter().GetResult();

                return(true);
            }

            return(false);
        }
Exemplo n.º 13
0
        public async Task <string> AddPostAsync(string blogid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUser(username, password);

            var newPost = new Models.Post
            {
                Title       = post.title,
                Slug        = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : Models.Post.CreateSlug(post.title),
                Content     = post.description,
                IsPublished = publish,
                Categories  = post.categories
            };

            if (post.dateCreated != DateTime.MinValue)
            {
                newPost.PubDate = post.dateCreated;
            }

            await _blog.SavePost(newPost);

            return(newPost.ID);
        }
Exemplo n.º 14
0
    public Task <bool> EditPostAsync(string postid, string username, string password, Post post, bool publish)
    {
        EnsureUser(username, password);

        return(TryExecuteAsync(async() =>
        {
            if (!Guid.TryParse(postid.Trim(), out var id))
            {
                throw new ArgumentException("Invalid ID", nameof(postid));
            }

            var cids = await GetCatIds(post.categories);
            if (cids.Length == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(post.categories));
            }

            var req = new PostEditModel
            {
                Title = post.title,
                Slug = post.wp_slug ?? ToSlug(post.title),
                EditorContent = post.description,
                Tags = post.mt_keywords,
                CategoryList = cids.Select(p => new CategoryCheckBox {
                    Id = p, IsChecked = true
                }).ToList(),
                LanguageCode = "en-us",
                IsPublished = publish,
                EnableComment = true,
                FeedIncluded = true,
                PublishDate = DateTime.UtcNow
            };

            await _mediator.Send(new UpdatePostCommand(id, req));
            return true;
        }));
    }
Exemplo n.º 15
0
        public async Task <bool> EditPostAsync(string postid, string username, string password, Post post, bool publish)
        {
            EnsureUser(username, password);

            try
            {
                if (!Guid.TryParse(postid.Trim(), out var id))
                {
                    throw new ArgumentException("Invalid ID", nameof(postid));
                }

                var cids = await GetCatIds(post.categories);

                if (cids.Length == 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(post.categories));
                }

                var req = new UpdatePostRequest
                {
                    Title               = post.title,
                    Slug                = post.wp_slug ?? ToSlug(post.title),
                    EditorContent       = post.description,
                    Tags                = post.mt_keywords?.Split(','),
                    CategoryIds         = cids,
                    ContentLanguageCode = "en-us",
                    IsPublished         = publish,
                    EnableComment       = true,
                    IsFeedIncluded      = true,
                    ExposedToSiteMap    = true,
                    PublishDate         = DateTime.UtcNow
                };

                await _postService.UpdateAsync(id, req);

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                throw new MetaWeblogException(e.Message);
            }
        }
Exemplo n.º 16
0
        public Task <string> AddPostAsync(string blogid, string username, string password, Post post, bool publish)
        {
            EnsureUser(username, password);

            return(TryExecuteAsync(async() =>
            {
                var cids = await GetCatIds(post.categories);
                if (cids.Length == 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(post.categories));
                }

                var req = new UpdatePostRequest
                {
                    Title = post.title,
                    Slug = post.wp_slug ?? ToSlug(post.title),
                    EditorContent = post.description,
                    Tags = post.mt_keywords?.Split(','),
                    CategoryIds = cids,
                    ContentLanguageCode = "en-us",
                    IsPublished = publish,
                    EnableComment = true,
                    IsFeedIncluded = true,
                    ExposedToSiteMap = true,
                    PublishDate = DateTime.UtcNow
                };

                var p = await _postManageService.CreateAsync(req);
                return p.Id.ToString();
            }));
        }
 public bool EditPost(string postid, string username, string password, Post post, bool publish)
 {
     return true;
 }
 public string AddPost(string blogid, string username, string password, Post post, bool publish)
 {
     return "123";
 }