From 2b7583b045ebdb8b945562792e8a3952b584fee8 Mon Sep 17 00:00:00 2001 From: MarcEricMartel <74071476+MarcEricMartel@users.noreply.github.com> Date: Sat, 8 Oct 2022 13:05:23 -0700 Subject: [PATCH] =?UTF-8?q?Pas=20s=C3=BBr=20pour=20le=20imagedata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/InventoryController.cs | 12 +++++------- .../Controllers/ProductController.cs | 10 +++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs index 20cf544..c18992d 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/InventoryController.cs @@ -8,19 +8,17 @@ namespace GrossesMitainesAPI.Controllers; [ApiController, Route("api/[controller]")] public class InventoryController : Controller { - private readonly ILogger _logger; private readonly InventoryContext _context; - public InventoryController(ILogger logger, InventoryContext context) { - _logger = logger; + public InventoryController(InventoryContext context) { _context = context; } [HttpGet(Name ="Inventory")] - public IEnumerable Get(int? last) { - if (!last.HasValue) - last = 1; - return _context.Products.Where(x => x.Id >= last && x.Id < last + 5).ToList(); + public IEnumerable Get(int? lastId) { + if (!lastId.HasValue) + lastId = 1; + return _context.Products.Where(x => x.Id >= lastId && x.Id < lastId + 5).ToList(); } } diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/ProductController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/ProductController.cs index 0af156a..f1775f8 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/ProductController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/ProductController.cs @@ -30,12 +30,20 @@ public class ProductController : Controller { [HttpPost(Name = "Product")] public void Post(Product prod) { - prod.Id = _context.Products.Count(); try { _context.Products.Add(prod); } catch (Exception e) { _logger.LogError(8, e.Message); } } + + [HttpPut(Name = "Product")] + public void Put(Product prod) { + try { + _context.Products.Update(prod); + } catch (Exception e) { + _logger.LogError(8, e.Message); + } + } }