0
Good afternoon guys, I don’t know why my parameter is not recognized, can you help me? The value does not arrive in c# but this present in the angle c#
[HttpGet]
[Route("carregarUsuarioPorId")]
public HttpResponseMessage BuscarUsuarioPorId()
{
try
{
WSS_RetornoListaDTO<Usuario> wss = new WSS_RetornoListaDTO<Usuario>();
int idUser = 0;
var req = Request.GetQueryNameValuePairs();
if (req != null)
{
foreach (var parameter in req)
{
if (parameter.Key.Equals("id"))
idUser = int.Parse(parameter.Value.ToString());
}
}
usuarioDAO = new UsuarioDAO();
wss.resultado = usuarioDAO.BuscarUsuarioPorId(idUser);
if (wss.resultado.Count > 0)
{
wss.codRetorno = 200;
wss.msgRetorno = "Sucesso";
return Request.CreateResponse<WSS_RetornoListaDTO<Usuario>>(HttpStatusCode.OK, wss);
}
else
return Request.CreateResponse(HttpStatusCode.NoContent, "Usuario não localizado");
}
catch (Exception e)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, "ERRO - " + e.Message);
}
}
parameter call:
getUserPorId: function (idUser) {
var id = [];
id[0] = idUser;
return
$http.get('http://localhost:61223/usuario/carregarUsuarioPorId',id)
.then(function (response) {
return response.data;
});
},
Just complementing, it is always interesting to put the parameter on the route as well:
[Route("carregarUsuarioPorId/{id:int:min(1)}")]
so I can restrict with Constraint what is my value in the URL.– Gabriel Coletta