From 49a13a412fdc8d6b3b6bbd8a285c5f4d4ba79bf4 Mon Sep 17 00:00:00 2001 From: Lynne Date: Wed, 16 Sep 2020 12:55:32 +1000 Subject: [PATCH] implemented basic API for getting documents --- Controllers/DocumentController.cs | 36 +++++++++++++++++++++++++++++++ Pages/Documents/Details.cshtml | 2 +- Pages/Shared/_Layout.cshtml | 2 +- Startup.cs | 1 + 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 Controllers/DocumentController.cs diff --git a/Controllers/DocumentController.cs b/Controllers/DocumentController.cs new file mode 100644 index 0000000..944a200 --- /dev/null +++ b/Controllers/DocumentController.cs @@ -0,0 +1,36 @@ +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>> GetDocuments() { + return await _context.Document.Take(25).ToListAsync(); + } + + [HttpGet("{id}")] + public async Task> GetDocumentById(int id) { + var document = await _context.Document.FindAsync(id); + + if (document == null) { + return NotFound(); + } + + return document; + } + } +} diff --git a/Pages/Documents/Details.cshtml b/Pages/Documents/Details.cshtml index 25ec72a..f5e260c 100644 --- a/Pages/Documents/Details.cshtml +++ b/Pages/Documents/Details.cshtml @@ -35,6 +35,6 @@ diff --git a/Pages/Shared/_Layout.cshtml b/Pages/Shared/_Layout.cshtml index 6af4d8d..c87eb01 100644 --- a/Pages/Shared/_Layout.cshtml +++ b/Pages/Shared/_Layout.cshtml @@ -10,7 +10,7 @@