Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created May 3, 2017 15:07
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 dcomartin/f58bce892641e241390aceb593945c55 to your computer and use it in GitHub Desktop.
Save dcomartin/f58bce892641e241390aceb593945c55 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using TodoApi.Models;
namespace TodoApi.Controllers
{
[Route("api/[controller]")]
public class TodoController : Controller
{
private readonly ITodoRepository _todoRepository;
public TodoController(ITodoRepository todoRepository)
{
_todoRepository = todoRepository;
}
[HttpGet]
public IEnumerable<TodoItem> GetAll()
{
return _todoRepository.GetAll();
}
[HttpGet("{id}", Name = "GetTodo")]
public IActionResult GetById(long id)
{
var item = _todoRepository.Find(id);
if (item == null)
{
return NotFound();
}
return new ObjectResult(item);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment