Exemple #1
0
        /// <summary>
        /// Inserir Produto - Informações basicas
        /// </summary>
        /// <returns></returns>
        public ProductDetail CreateProductInformation(string token, ProductInformationCreate product)
        {
            try
            {
                _logger.LogInformation("Criar informações basicas - Produto: Enviando requisição para a API");
                var response = _ProductApi.CreateProductInformation(token, product).Result;
                if (!response.IsSuccessStatusCode)
                {
                    var contentResult = response.Content.ReadAsStringAsync().Result;
                    _logger.LogError($"Criar informações basicas - Produto: API retornou erro :( - {response.StatusCode}-{response.ReasonPhrase} -> {contentResult}");
                    if (((int)response.StatusCode) >= 400 && ((int)response.StatusCode) < 500)
                    {
                        return(null);
                    }
                }
                _logger.LogInformation("Criar informações basicas - Produto: API retornou sucesso :)");

                var json = response.Content.ReadAsStringAsync().Result;
                return(Task.Factory.StartNew(() => JsonConvert.DeserializeObject <ProductDetail>(json)).Result);
            }
            catch (Exception)
            {
                _logger.LogError($"Criar informações basicas - Produto: API retornou erro :(");
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// Inserir Produto - Informações basicas
        /// </summary>
        /// <returns></returns>
        public async Task <HttpResponseMessage> CreateProductInformation(string token, ProductInformationCreate product)
        {
            _client             = new HttpClient();
            _client.BaseAddress = AppSettings.Apis.ProductApi;
            _client.DefaultRequestHeaders.Accept.Clear();
            _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            return(await new HttpClientHelper(_client)
                   .SetEndpoint("products/information")
                   .AddHeader("Authorization", $"Bearer {token}")
                   .WithContentSerialized(product)
                   .PostAsync());
        }