Exemplo n.º 1
0
        /// <summary>
        /// Creates a new article on the given blog.
        /// </summary>
        /// <param name="blogId">The blog that the article will belong to.</param>
        /// <param name="article">The article being created. Id should be null.</param>
        /// <param name="metafields">Optional metafield data that can be returned by the <see cref="MetaFieldService"/>.</param>
        /// <param name="cancellationToken">Cancellation Token</param>
        public virtual async Task <Entities.Article> CreateAsync(long blogId, Entities.Article article, IEnumerable <Entities.MetaField> metafields = null, CancellationToken cancellationToken = default)
        {
            var req  = PrepareRequest($"blogs/{blogId}/articles.json");
            var body = article.ToDictionary();

            if (metafields != null)
            {
                body.Add("metafields", metafields);
            }

            var content = new JsonContent(new
            {
                article = body
            });

            var response = await ExecuteRequestAsync <Entities.Article>(req, HttpMethod.Post, cancellationToken, content, "article");

            return(response.Result);
        }