Wenxamarin - Web API

Asked

Viewed 20 times

0

I’m trying to make the code of the Post Api and I’m not able to save the information, since it comes from a relationship between two tables. It is a sales system, where I have two tables, one that is called Ordempedido, where is the customer information, form of payment and a second where is stored the details of this order as the products that the customer wants to buy, however when generating the Post Api I can only save part of the order which refers to the customer information and payment method and does not save the details of my order, that is, the products do not display.

// POST: api/OrdemPedidoes
    [ResponseType(typeof(OrdemPedido))]
    public IHttpActionResult PostOrdemPedido(OrderRequest orderRequest)
    {
        var details = new List<OrderDetailldTmp>();
        foreach (var detail in orderRequest.Detalhes)
        {
            var product = db.CadProdutoes.Find(detail.ProdutoId);
            if (product != null)
            {
                details.Add(new OrderDetailldTmp
                {
                    Descricao = product.Descricao,
                    Price = product.Precoprazo,
                    ProdutoId = product.ProdutoId,
                    Quantity = detail.Quantity,
                    Desconto = detail.Desconto,

                });
            }
        }

        var newOrderView = new NewOrderView
        {
            Details = details,
            IdCliente = orderRequest.IdCliente,
            Date = orderRequest.Date,
            CityId = orderRequest.CityId,
            FormaPagamentoId = orderRequest.FormaPagamentoId,
            FornecedorId = orderRequest.FornecedorId,
            DataEntrega = orderRequest.DataEntrega,
            HoraIncial = orderRequest.HoraIncial,
            Remarks = orderRequest.Remarks
        };



        var response = MovementsHelper.NewOrder(newOrderView);

        if (response.Succeeded)
        {
            return Ok("Venda Salva!!");
        }

        return BadRequest(response.Message);
    }
  • Hello @Grasielle, unfortunately with the code you shared not to help you much, but according to your sayings, I believe that the problem is occurring in one or two moments, when it comes to serialize the data to send to the service, or at the time of the service to deserialize the data sent.

  • If possible I suggest you put the service to run in debug mode put a stop point (breakpoint) on the controller that receives the request and inspect the received object so you can see if the data is arriving correctly, otherwise the problem is on the client side(mobile app)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.