Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Last active April 2, 2020 15:50
Show Gist options
  • Save gavilanch/d1d1296a7ead28428b49ba4a3b2e9c04 to your computer and use it in GitHub Desktop.
Save gavilanch/d1d1296a7ead28428b49ba4a3b2e9c04 to your computer and use it in GitHub Desktop.
[HttpGet]
public ActionResult<IEnumerable<Autor>> Get()
{
logger.LogInformation("Obteniendo los autores");
return context.Autores.ToList();
}
[HttpGet("{id}")]
public async Task<ActionResult<Autor>> Get(int id)
{
logger.LogDebug("Buscando autor de id " + id.ToString());
var autor = await context.Autores.FirstOrDefaultAsync(x => x.Id == id);
if (autor == null)
{
logger.LogWarning($"El autor de Id {id} no ha sido encontrado");
return NotFound();
}
return autor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment