public HttpContent Create() { if (HttpStreamContent == null) { throw new NullReferenceException($"{nameof(HttpStreamContent)} cannot be null."); } if (!string.IsNullOrEmpty(AltText)) { HttpStreamContent.Headers.TryAddWithoutValidation("alt_text", AltText); } if (!string.IsNullOrEmpty(Caption)) { HttpStreamContent.Headers.TryAddWithoutValidation("caption", Caption); } if (!string.IsNullOrEmpty(Description)) { HttpStreamContent.Headers.TryAddWithoutValidation("description", Description); } if (AssociatedPostId >= 0) { HttpStreamContent.Headers.TryAddWithoutValidation("post", AssociatedPostId.ToString()); } if (!string.IsNullOrEmpty(Title)) { HttpStreamContent.Headers.TryAddWithoutValidation("title", Title); } if (AuthorId >= 0) { HttpStreamContent.Headers.TryAddWithoutValidation("author", AuthorId.ToString()); } HttpStreamContent.Headers.TryAddWithoutValidation("comment_status", CommandStatus.ToString().ToLower()); HttpStreamContent.Headers.TryAddWithoutValidation("ping_status", PingStatus.ToString().ToLower()); return(HttpStreamContent); }
/// <summary> /// <inheritdoc /> /// </summary> /// <returns></returns> public HttpContent Create() { Dictionary <string, string> formData = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(Content)) { formData.Add("content", Content); } if (!string.IsNullOrEmpty(Title)) { formData.Add("title", Title); } if (!string.IsNullOrEmpty(Slug)) { formData.Add("slug", Slug); } if (!string.IsNullOrEmpty(Password)) { formData.Add("password", Password); } if (AuthorId > 0) { formData.Add("author", AuthorId.ToString()); } if (!string.IsNullOrEmpty(Excerpt)) { formData.Add("excerpt", Excerpt); } if (FeaturedImageId > 0) { formData.Add("featured_media", FeaturedImageId.ToString()); } if (Sticky) { formData.Add("sticky", "1"); } if (Categories != null && Categories.Length > 0) { formData.Add("categories", string.Join(',', Categories)); } if (Tags != null && Tags.Length > 0) { formData.Add("tags", string.Join(',', Tags)); } if (PostDate != DateTime.MinValue) { formData.Add("date", PostDate.ToString()); } formData.Add("comment_status", CommandStatus.ToString().ToLower()); formData.Add("ping_status", PingStatus.ToString().ToLower()); formData.Add("format", Format.ToString().ToLower()); formData.Add("status", Status.ToString().ToLower()); return(new FormUrlEncodedContent(formData)); }