/// <summary>
        /// Creates a new <see cref="ShopifyProduct"/> on the store.
        /// </summary>
        /// <param name="product">A new <see cref="ShopifyProduct"/>. Id should be set to null.</param>
        /// <param name="options">Options for creating the product.</param>
        /// <returns>The new <see cref="ShopifyProduct"/>.</returns>
        public async Task<ShopifyProduct> CreateAsync(ShopifyProduct product, ShopifyProductCreateOptions options = null)
        {
            IRestRequest req = RequestEngine.CreateRequest("products.json", Method.POST, "product");

            //Build the request body
            Dictionary<string, object> body = new Dictionary<string, object>(options?.ToDictionary() ?? new Dictionary<string, object>())
            {
                { "product", product }
            };

            req.AddJsonBody(body);

            return await RequestEngine.ExecuteRequestAsync<ShopifyProduct>(_RestClient, req);
        }
Example #2
0
        /// <summary>
        /// Creates a new <see cref="ShopifyProduct"/> on the store.
        /// </summary>
        /// <param name="product">A new <see cref="ShopifyProduct"/>. Id should be set to null.</param>
        /// <param name="options">Options for creating the product.</param>
        /// <returns>The new <see cref="ShopifyProduct"/>.</returns>
        public async Task <ShopifyProduct> CreateAsync(ShopifyProduct product, ShopifyProductCreateOptions options = null)
        {
            IRestRequest req = RequestEngine.CreateRequest("products.json", Method.POST, "product");

            //Build the request body
            Dictionary <string, object> body = new Dictionary <string, object>(options?.ToDictionary() ?? new Dictionary <string, object>())
            {
                { "product", product }
            };

            req.AddJsonBody(body);

            return(await RequestEngine.ExecuteRequestAsync <ShopifyProduct>(_RestClient, req));
        }
        /// <summary>
        /// Creates a new <see cref="ShopifyProduct"/> on the store.
        /// </summary>
        /// <param name="product">A new <see cref="ShopifyProduct"/>. Id should be set to null.</param>
        /// <param name="options">Options for creating the product.</param>
        /// <returns>The new <see cref="ShopifyProduct"/>.</returns>
        public async Task<ShopifyProduct> CreateAsync(ShopifyProduct product, ShopifyProductCreateOptions options = null)
        {
            IRestRequest req = RequestEngine.CreateRequest("products.json", Method.POST, "product");

            //Build the request body as a dictionary. Necessary because the create options must be added to the 
            //'product' property.
            var productBody = product.ToDictionary();

            if(options != null)
            {
                foreach(var kvp in options.ToDictionary())
                {
                    productBody.Add(kvp);
                }
            }

            var requestBody = new { product = productBody };

            req.AddJsonBody(requestBody);

            return await RequestEngine.ExecuteRequestAsync<ShopifyProduct>(_RestClient, req);
        }
Example #4
0
        /// <summary>
        /// Creates a new <see cref="ShopifyProduct"/> on the store.
        /// </summary>
        /// <param name="product">A new <see cref="ShopifyProduct"/>. Id should be set to null.</param>
        /// <param name="options">Options for creating the product.</param>
        /// <returns>The new <see cref="ShopifyProduct"/>.</returns>
        public async Task <ShopifyProduct> CreateAsync(ShopifyProduct product, ShopifyProductCreateOptions options = null)
        {
            IRestRequest req = RequestEngine.CreateRequest("products.json", Method.POST, "product");

            //Build the request body as a dictionary. Necessary because the create options must be added to the
            //'product' property.
            var productBody = product.ToDictionary();

            if (options != null)
            {
                foreach (var kvp in options.ToDictionary())
                {
                    productBody.Add(kvp);
                }
            }

            var requestBody = new { product = productBody };

            req.AddJsonBody(requestBody);

            return(await RequestEngine.ExecuteRequestAsync <ShopifyProduct>(_RestClient, req));
        }