Skip to content

Instantly share code, notes, and snippets.

@nishanc
Last active May 5, 2019 13:12
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 nishanc/55d8b650074627c8fad7a3edd79fd7b0 to your computer and use it in GitHub Desktop.
Save nishanc/55d8b650074627c8fad7a3edd79fd7b0 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using JWTAuth.API.Data;
using Microsoft.EntityFrameworkCore;
namespace JWTAuth.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
private readonly DataContext _context;
public ValuesController(DataContext context)
{
_context = context;
}
// GET api/values
[HttpGet]
public async Task<IActionResult> GetValues()
{
var values = await _context.Values.ToListAsync();
return Ok(values);
}
// GET api/values/5
[HttpGet("{id}")]
public async Task<IActionResult> GetValue(int id)
{
var value = await _context.Values.FirstOrDefaultAsync(x => x.Id == id);
return Ok(value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment