/// <summary> /// The EditPost /// </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="bool" /></returns> public bool EditPost( string postId, string userId, string password, Post post, bool publish) { ValidateUser(userId, password); Models.Post 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); }
/// <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); }
/// <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); }
/// <summary> /// The GetPostAsync /// </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> /// <returns>The <see cref="Task{Post}" /></returns> public async Task <Post> GetPostAsync(string postId, string userId, string password) { ValidateUser(userId, password); Models.Post post = await _blog.GetPostById(postId); return(post != null?ToMetaWebLogPost(post) : null); }
/// <summary> /// The GetPost /// </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> /// <returns>The <see cref="Post" /></returns> public Post GetPost(string postId, string userId, string password) { ValidateUser(userId, password); Models.Post post = _blog.GetPostById(postId) .GetAwaiter() .GetResult(); if (post != null) { return(ToMetaWebLogPost(post)); } return(null); }
/// <summary> /// The ToMetaWebLogPost /// </summary> /// <param name="post">The post<see cref="Models.Post" /></param> /// <returns>The <see cref="Post" /></returns> private Post ToMetaWebLogPost(Models.Post post) { HttpRequest request = _context.HttpContext.Request; string 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() }); }
/// <summary> /// The DeletePostAsync /// </summary> /// <param name="key">The key<see cref="string" /></param> /// <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="publish">The publish<see cref="bool" /></param> /// <returns> /// The /// <see> /// <cref>Task{bool}</cref> /// </see> /// </returns> public async Task <bool> DeletePostAsync( string key, string postId, string userId, string password, bool publish) { ValidateUser(userId, password); Models.Post post = await _blog.GetPostById(postId); if (post == null) { return(false); } await _blog.DeletePost(post); return(true); }
/// <summary> /// The DeletePost /// </summary> /// <param name="key">The key<see cref="string" /></param> /// <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="publish">The publish<see cref="bool" /></param> /// <returns>The <see cref="bool" /></returns> public bool DeletePost( string key, string postId, string userId, string password, bool publish) { ValidateUser(userId, password); Models.Post post = _blog.GetPostById(postId) .GetAwaiter() .GetResult(); if (post != null) { _blog.DeletePost(post) .GetAwaiter() .GetResult(); return(true); } return(false); }