Service not being called to update on the bank

1

I made a service and when I call on the URL , passing the proper parameters, does not work:

Call URL :

http://localhost:9078/api/atualiza/1000012120/teste

My service:

public class AtualizaController : ApiController
    {
        AutorizadorContext contexto = new AutorizadorContext();
        PedidoLiberacao liberacao = new PedidoLiberacao();

        [AcceptVerbs("Put")]
        public void putItensLiberacao(int id, [FromBody]string value)
        {
            liberacao.AtualizaLiberacao(id, value);
        }
    }

This is the method the service calls and upgrades in the DB:

[Route("atualiza/{id}/{value}")]
        public void AtualizaLiberacao(int id, string value)
        {
            var lista = contexto.Liberacoes
                        .Where(l => l.IdOrcamento == id).ToList();

            lista.ForEach(f =>
            {
                f.FlagLiberacao = 0;
                f.AutorizouReceberAtrazado = value;
            });

            contexto.SaveChanges();

        }

You're giving ERROR :

  

page not found (404)

EDIT2

The error above does not have more, but gives this error (Postman):

  

{       "Message": "The requested resource does not support the http 'GET' method." }

So my service and method stayed

[RoutePrefix("api/Atualiza")]
    public class AtualizaController : ApiController
    {
        AutorizadorContext contexto = new AutorizadorContext();
        PedidoLiberacao liberacao = new PedidoLiberacao();

        [Route("{id}/{value}")]
        [AcceptVerbs("Put")]
        public void putItensLiberacao(int id, [FromBody]string value)
        {
            liberacao.AtualizaLiberacao(id, value);
        }
    }

and the

[Route("atualiza/{id}/{value}")]
        public void AtualizaLiberacao(int id, string value)
        {
            var lista = contexto.Liberacoes
                        .Where(l => l.IdOrcamento == id).ToList();

            lista.ForEach(f =>
            {
                f.FlagLiberacao = 0;
                f.AutorizouReceberAtrazado = value;
            });
            contexto.SaveChanges();
        }

In the method I commented the attribute, but the error persists. I put a break point in the service and did not even get in.

    
asked by anonymous 14.09.2017 / 16:23

1 answer

4

It turns out that you are using attribute definition, so you need to define the full path of the service (this includes api /).

You can use the RoutePrefix attribute to not need to repeat the default part of the routes

[RoutePrefix("api/Atualiza")]
public class AtualizaController : ApiController
{
    [Route("{id}/{value}")]
    public void AtualizaLiberacao(int id, string value) { }
}
    
14.09.2017 / 16:44