public async Task <IActionResult> UpdatePost(Post post) { if (!ModelState.IsValid) { return(View("Edit", post)); } Post existing = await _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 = !string.IsNullOrWhiteSpace(post.Slug) ? post.Slug.Trim() : PostBase.CreateSlug(post.Title); existing.IsPublished = post.IsPublished; existing.Content = post.Content.Trim(); existing.Excerpt = post.Excerpt.Trim(); await SaveFilesToDisk(existing); await _blog.SavePost(existing); return(Redirect(post.GetEncodedLink())); }
/// <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); }