Esempio n. 1
0
        public static async Task <bool> UpdPreco(PrecoL _preco)
        {
            LoadClient();

            try
            {
                string uri                   = _base_path + "/api/v1/precos";
                var    json                  = JsonConvert.SerializeObject(_preco);
                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);
        }
Esempio n. 2
0
 public static string GetJsonPrecos(PrecoL _item)
 {
     return(JsonConvert.SerializeObject(_item));
 }