Esempio n. 1
0
        public static async Task <string> CreateItemsAsync(AuthenticationProvider authenticationProvider, ProductResource product)
        {
            try
            {
                SalesItemResource resource = Mappers.ToItem(product);

                return(await ItemsController.InsertItemToIEAsync(authenticationProvider, resource).ConfigureAwait(false));
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
Esempio n. 2
0
        public static async Task <string> InsertItemToIEAsync(AuthenticationProvider authenticationProvider, SalesItemResource resource)
        {
            // Create the HTTP client to perform the request

            using (HttpClient client = new HttpClient())
            {
                await authenticationProvider.SetAccessTokenAsync(client);

                var jsonInvoices = new StringContent(
                    JsonSerializer.Serialize(resource),
                    Encoding.UTF8,
                    "application/json");

                string url = string.Format(
                    InvoicingEngineRoutes.ItemPostRoute,
                    Constants.baseAppUrl,
                    Identity.Account,
                    Identity.Subscription,
                    InvoicingEngineRoutes.ItemUrlBase);

                var response = await client.PostAsync(url, jsonInvoices).ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsStringAsync());
                }
                else
                {
                    throw new Exception(await response.Content.ReadAsStringAsync());
                }
            }
        }