1
I did a job and when I call on URL, passing the appropriate parameters, does not work:
Call on 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 that the service calls and updates in BD:
[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();
}
Is giving ERROR:
page not found(404)
EDIT2
The above error no longer has, but gives this error(Postman):
{ "Message": "The requested resource does not support the http 'GET' method'." }
So was my service and method
[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 method
[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 enter.
Put in your Controller class (above the setting)
[RoutePrefix("api/")]
doing you a favor.– Gabriel Coletta