Snootalogue/Controllers/DocumentController.cs

36 lines
901 B
C#

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 Snootalogue.Models;
using Snootalogue.Data;
namespace Snootalogue.Controllers {
[Route("/api/[controller]")]
[ApiController]
public class DocumentController : ControllerBase {
private readonly SnootalogueContext _context;
public DocumentController(SnootalogueContext context) {
_context = context;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<Document>>> GetDocuments() {
return await _context.Document.Take(25).ToListAsync();
}
[HttpGet("{id}")]
public async Task<ActionResult<Document>> GetDocumentById(int id) {
var document = await _context.Document.FindAsync(id);
if (document == null) {
return NotFound();
}
return document;
}
}
}