Api with Array of items does not receive the data posted

0

I have an Api that receives the data posted as it shows the image, it happens that the data is coming empty, I appreciate the help.

//http://localhost:49764/api/unidade/carrinho/consultaUnidadeAtendimento[HttpPost][Route("unidade/carrinho/consultaUnidadeAtendimento")]
        public HttpResponseMessage ConsultaUnidadeAtendimento(ConsultaUnidadeAtendimentoModel consultaAtendimento)
        {

            try
            {
                string numeroCarrinho = consultaAtendimento.NumeroCarrinho.ToString();
                string cep = consultaAtendimento.Cep;
                bool retiraLocal = consultaAtendimento.RetiraNoLocal;

               var tTabela = "";
               var listar = "";
               return Request.CreateResponse(HttpStatusCode.OK, new { usuario = listar.ToArray() });
            }
            catch (Exception ex)
            {

                return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }

        }



        public class ConsultaUnidadeAtendimentoModel
        {
            [JsonProperty("numeroCarrinho")]
            public long NumeroCarrinho { get; set; }

            [JsonProperty("itens")]
            public dynamic Itens { get; set; }

            [JsonProperty("cep")]
            public string Cep { get; set; }

            [JsonProperty("retiraNoLocal")]
            public bool RetiraNoLocal { get; set; }
        }
    
asked by anonymous 07.12.2017 / 13:30

2 answers

1

attempts to send JSON object changes in postman

So you work with object gets simpler

 public class Model
    {
        [JsonProperty("numeroCarrinho")]
        public long NumeroCarrinho { get; set; }

        [JsonProperty("itens")]
        public List<Carrinho> Itens { get; set; }

        [JsonProperty("cep")]
        public string Cep { get; set; }

        [JsonProperty("retiraNoLocal")]
        public bool RetiraNoLocal { get; set; }
    }

    public class Carrinho
    {
        [JsonProperty("codigo")]
        public string Codigo { get; set; }
        [JsonProperty("qtd")]
        public int Qtd { get; set; }
    }

json uploaded

 {
        "numeroCarrinho":122865,
        "itens":[
            {"codigo":"PA00058","qtd":1},
            {"codigo":"MA00068","qtd":1},
            {"codigo":"PA00004","qtd":1}
        ],
        "cep":"41706670",
        "retiradaNoLocal":false
    }
    
07.12.2017 / 14:08
1

You can not receive Objeto C# in the request parameter, you get the JSON (string) and then deserializa the same.

    
07.12.2017 / 13:41