60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
using api.Data;
|
||
|
using Microsoft.AspNetCore.Authorization;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
||
|
namespace api.Controllers
|
||
|
{
|
||
|
|
||
|
[Route("api/[controller]")]
|
||
|
[ApiController]
|
||
|
public class ValuesController : ControllerBase
|
||
|
{
|
||
|
private readonly DataContext context;
|
||
|
public ValuesController(DataContext context)
|
||
|
{
|
||
|
this.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)
|
||
|
{
|
||
|
//procura o primeiro ou o default (que é null)
|
||
|
var value= await context.Values.FirstOrDefaultAsync(x => x.id == id);
|
||
|
|
||
|
return Ok(value);
|
||
|
}
|
||
|
|
||
|
// POST api/values
|
||
|
[HttpPost]
|
||
|
public void Post([FromBody] string value)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
// PUT api/values/5
|
||
|
[HttpPut("{id}")]
|
||
|
public void Put(int id, [FromBody] string value)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
// DELETE api/values/5
|
||
|
[HttpDelete("{id}")]
|
||
|
public void Delete(int id)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
}
|