Last active
March 17, 2019 05:36
-
-
Save uranio-235/4525d02a3b9ab0067cdbf4eb772d7ef6 to your computer and use it in GitHub Desktop.
Resulta interesante como ActionResult<T> permite a un controlador devolver tanto un valor como un error. Sin embargo, mantiene la tipografía rígida.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Route(@"api/")] | |
[Produces(@"application/json")] | |
public class ApiController : Controller | |
{ | |
// inicializa la base de datos | |
public EtecsaContext etecsa { get; set; } = new EtecsaContext() { Fichero=@"D:\db\Etecsa.db" }; | |
// note como ActionResult<Movil> permite retornar un móvil o un StatucCode | |
[HttpGet("query/{numero}")] | |
public ActionResult<Movil> Consulta(string numero) | |
{ | |
// intenta localizar le móvil | |
resultado = etecsa.Movil.FirstOrDefault(m => m.Number == numero); | |
// si se cogió tíralo, si no, error 503 | |
if (resultado == null) | |
return StatusCode(503); | |
else | |
return fijo; | |
} // Consulta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment