public static async Task <bool> GetEstoque(string _produtoId = "") { LoadClient(); _message = ""; try { string uri = _base_path + "/api/estoque" + (_produtoId.Length > 0 ? "/" : "") + _produtoId; HttpResponseMessage response = await _client.GetAsync(uri); var property = response.GetType().GetProperty("StatusCode"); if ((HttpStatusCode)property.GetValue(response) == HttpStatusCode.OK) { response.EnsureSuccessStatusCode(); DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(EstoqueC)); _estoque = (EstoqueC)jsonSerializer.ReadObject(await response.Content.ReadAsStreamAsync()); return(true); } } catch (Exception e) { _message = e.Message; } return(false); }
public static async Task <bool> UpdEstoque(EstoqueC _estoque) { LoadClient(); _message = ""; try { string uri = _base_path + "/api/estoque"; var json = JsonConvert.SerializeObject(_estoque); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _client.PutAsync(new Uri(uri), stringContent); var property = response.GetType().GetProperty("StatusCode"); if ((HttpStatusCode)property.GetValue(response) == HttpStatusCode.OK) { response.EnsureSuccessStatusCode(); _message = "HttpStatus.200"; return(true); } if ((HttpStatusCode)property.GetValue(response) == HttpStatusCode.BadRequest) { _message = "HttpStatus.400"; return(false); } if ((HttpStatusCode)property.GetValue(response) == HttpStatusCode.InternalServerError) { _message = "HttpStatus.500"; return(false); } } catch (Exception e) { _message = e.Message; } return(false); }