Пример #1
0
        public HttpResponseMessage Calcula([FromBody] RequestFrete request)
        {
            HttpResponseMessage response;

            try
            {
                _help.ShowValidation(request);

                var _ret = _dall.GetFreteValor(request);

                return(Request.CreateResponse(HttpStatusCode.OK, _ret));
            }
            catch (SqlException ex)
            {
                webError = _help.WebException(ex);
                response = Request.CreateResponse(webError.Data.HttpStatusCode, webError);
            }
            catch (ArgumentException arg)
            {
                webError = _help.WebException(arg);
                response = Request.CreateResponse(webError.Data.HttpStatusCode, webError);
            }
            catch (Exception ex)
            {
                webError = _help.WebException(ex);
                response = Request.CreateResponse(webError.Data.HttpStatusCode, webError);
            }

            return(response);
        }
Пример #2
0
        public ResultFrete GetFreteValor(RequestFrete model)
        {
            cad = new RestClient("http://localhost:51732/");
            RestRequest request = new RestRequest("api/v1/frete/calcula", Method.POST);

            request.AddJsonBody(model);
            request.AddHeader("Content-Type", "application/json");

            var response = cad.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ArgumentException(JsonConvert.DeserializeObject <response>(response.Content).Data?.Message);
            }

            var _result = JsonConvert.DeserializeObject <ResultFrete>(response.Content);

            return(_result);
        }