Scopri come trovare i migliori animatori per i tuoi eventi di animazione in questo articolo. Ti forniremo suggerimenti pratici e strategie efficaci per scegliere professionisti qualificati, garantendo un intrattenimento di alta qualità e un'esperienza indimenticabile per i tuoi ospiti.
Trova professionisti vicino a te
Trova professionisti
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApi.Models;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class PessoasController : ControllerBase
{
private readonly APIDB _context;
public PessoasController(APIDB context)
{
_context = context;
}
// GET: api/Pessoas
[HttpGet]
public async Task>> GetPessoas()
{
return await _context.Pessoas.ToListAsync();
}
// GET: api/Pessoas/5
[HttpGet("{id}")]
public async Task> GetPessoa(int id)
{
var pessoa = await _context.Pessoas.FindAsync(id);
if (pessoa == null)
{
return NotFound();
}
return pessoa;
}
// PUT: api/Pessoas/5
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id}")]
public async Task PutPessoa(int id, Pessoa pessoa)
{
if (id != pessoa.Id)
{
return BadRequest();
}
_context.Entry(pessoa).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!PessoaExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return NoContent();
}
// POST: api/Pessoas
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPost]
public async Task> PostPessoa(Pessoa pessoa)
{
_context.Pessoas.Add(pessoa);
await _context.SaveChangesAsync();
return CreatedAtAction("GetPessoa", new { id = pessoa.Id }, pessoa);
}
// DELETE: api/Pessoas/5
[HttpDelete("{id}")]
public async Task> DeletePessoa(int id)
{
var pessoa = await _context.Pessoas.FindAsync(id);
if (pessoa == null)
{
return NotFound();
}
_context.Pessoas.Remove(pessoa);
await _context.SaveChangesAsync();
return pessoa;
}
private bool PessoaExists(int id)
{
return _context.Pessoas.Any(e => e.Id == id);
}
}
}