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);
        }
Пример #2
0
        private static Post LoadCategories(Post post, XElement doc)
        {
            XElement categories = doc.Element("categories");

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

            List <string> list = new List <string>();

            foreach (var node in categories.Elements("category"))
            {
                list.Add(node.Value);
            }

            return(PostModule.WithCategories(string.Join(",", list), post));
        }
        public async Task <IActionResult> UpdatePost(Post post)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", post));
            }

            var existing = await _blog.GetPostById(post.ID) ?? post;

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

            existing = PostModule.UpdateWith(existing, post);
            existing = PostModule.WithCategories(categories, post);

            await _blog.SavePost(existing);

            await SaveFilesToDisk(existing);

            return(Redirect(PostModule.GetLink(existing)));
        }
        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);
        }