/// <summary> /// Alterar Produto - Informações basicas /// </summary> /// <returns></returns> public ProductDetail UpdateProductInformation(string token, string id, ProductInformationUpdate product) { try { _logger.LogInformation("Alterar informações basicas - Produto: Enviando requisição para a API"); var response = _ProductApi.UpdateProductInformation(token, id, product).Result; if (!response.IsSuccessStatusCode) { var contentResult = response.Content.ReadAsStringAsync().Result; _logger.LogError($"Alterar 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("Alterar 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($"Alterar informações basicas- Produto: API retornou erro :( "); return(null); } }
/// <summary> /// Alterar Produto - Informações basicas /// </summary> /// <returns></returns> public async Task <HttpResponseMessage> UpdateProductInformation(string token, string id, ProductInformationUpdate 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/{id}/information") .AddHeader("Authorization", $"Bearer {token}") .WithContentSerialized(product) .PutAsync()); }