send array post in AngularJS

0

Talk to people, blz? I have a question to send two attributes to an api with authentication. I need to do this with angular JS. This is the C # code of the API method:

[Route("cadastrarProduto")]
    [ApplyModelValidation]
    public IHttpActionResult PostCadastrar(Array idfornecedor, [FromBody]produto produto)
    {
        try
        {
            var retorno = _produtoServico.Cadastrar(produto);

            if (retorno == "OK")
            {
                return Created($"{Request.RequestUri}/{produto.Id}","Produto cadastrado corretamente");                    
            }
            else
            {
                return Ok(retorno);
            }
        }
        catch (Exception ex)
        {
            var retorno = "Erro ao cadastrar produto " + produto.Nome + " verifique dadso informados.\n" + ex.InnerException.InnerException.Message;
            return BadRequest(retorno);
        }
    }

My factory in angulaJS is like this

cadastrar: function (produto) {

        try {
            var url = server + 'cadastrarProduto';
            return $http.post(url, produto, { headers: { 'Authorization': 'Bearer ' + token } }).then(
                function (result) {
                    return result.data;
                },
                function (erro) {
                    if (erro.statusText == 'Unauthorized') {
                        return erro.statusText
                    } else {
                        erro.data.modelState.push
                        var array = $.map(erro.data.modelState, function (value, index) {
                            return [value];
                        });
                        return array;
                    }
                });
        } catch (e) {

        }
    },

When I did not need to pass this array from idFornecedor, my factory worked fine, but now informing this array too, in my controller of AngularJS nothing would change, since this array is populated in another .js file and I already realized that it arrives right at my factory, I've spent more than 3 hours searching for it on the internet but nothing helped me. Does anyone here know how to fix this ???

    
asked by anonymous 21.06.2018 / 03:08

0 answers