Skip to content

Instantly share code, notes, and snippets.

@uranio-235
Last active March 17, 2019 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uranio-235/4525d02a3b9ab0067cdbf4eb772d7ef6 to your computer and use it in GitHub Desktop.
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.
[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