예제 #1
0
        public static async Task <bool> UpdEstoque(EstoqueL _estoque)
        {
            LoadClient();

            try
            {
                string uri                   = _base_path + "/api/v1/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);
        }
예제 #2
0
 public static string GetJsonEstoque(EstoqueL _item)
 {
     return(JsonConvert.SerializeObject(_item));
 }