This message I get in the browser or postman
"Message": "No HTTP resources were found matching the Request URI ' link '. ", "MessageDetail": "No action was found in the Items Controller that matches the request."
The problem is that I'm building a service where I pass an ID in the url so that only the items in that budget come in. In the controller it looks like this:
public class ItensController : ApiController
{
AutorizadorContext contexto = new AutorizadorContext();
ItensLiberacao itens = new ItensLiberacao();
[AcceptVerbs("Get")]
public IEnumerable<ItensLibDTO> getItensLiberacao(int idorcamento)
{
return itens.getItensLib(idorcamento).AsEnumerable().ToList();
}
}
And here the class ItemsLiberation:
public class ItensLiberacao
{
AutorizadorContext contexto = new AutorizadorContext();
ItensLibDTO libDTO = new ItensLibDTO();
public List<ItensLibDTO> getItensLib(int idorcamento)
{
var lista = contexto.ItensLibs
.Where(itens => itens.IdOrcamento == idorcamento)
.Select(item => new ItensLibDTO
{
Produto = item.Produto,
Qtde = item.Qtde.ToString(),
Unitario = item.Unitario.ToString(),
Custo = item.Custo.ToString(),
CustoDiario = item.CustoDiario.ToString(),
UltCondicao = item.UltCondicao.ToString(),
Total = item.Total.ToString()
}).ToList();
return lista;
}
}
How do I resolve this? What is missing most for the service to work? The number: 1000012105 is the ID of an existing budget in the database.
EDIT1
I changed my service to this and the same error continues:
[AcceptVerbs("Get")]
public HttpResponseMessage getItensLiberacao(int idorcamento)
{
var _itens = contexto.ItensLibs.Where(it => it.IdOrcamento == idorcamento).FirstOrDefault();
return Request.CreateResponse(HttpStatusCode.OK, _itens);
}
EDIT2
If I change the method and the service works, like this:
public class ItensLiberacao
{
AutorizadorContext contexto = new AutorizadorContext();
ItensLibDTO libDTO = new ItensLibDTO();
public List<ItensLibDTO> getItensLib()
{
var lista = contexto.ItensLibs
//.Where(itens => itens.IdOrcamento == idorcamento)
.Select(item => new ItensLibDTO
{
Produto = item.Produto,
Qtde = item.Qtde.ToString(),
Unitario = item.Unitario.ToString(),
Custo = item.Custo.ToString(),
CustoDiario = item.CustoDiario.ToString(),
UltCondicao = item.UltCondicao.ToString(),
Total = item.Total.ToString()
}).ToList();
return lista;
}
}
And the service:
public class ItensController : ApiController
{
AutorizadorContext contexto = new AutorizadorContext();
ItensLiberacao itens = new ItensLiberacao();
[AcceptVerbs("Get")]
public IEnumerable<ItensLibDTO> getItensLiberacao()
{
return itens.getItensLib().AsEnumerable().ToList();
}
}