Pas sûr pour le imagedata

This commit is contained in:
MarcEricMartel 2022-10-08 13:05:23 -07:00
parent 9de1611b5a
commit 2b7583b045
2 changed files with 14 additions and 8 deletions

View File

@ -8,19 +8,17 @@ namespace GrossesMitainesAPI.Controllers;
[ApiController, Route("api/[controller]")]
public class InventoryController : Controller {
private readonly ILogger<InventoryController> _logger;
private readonly InventoryContext _context;
public InventoryController(ILogger<InventoryController> logger, InventoryContext context) {
_logger = logger;
public InventoryController(InventoryContext context) {
_context = context;
}
[HttpGet(Name ="Inventory")]
public IEnumerable<Product> Get(int? last) {
if (!last.HasValue)
last = 1;
return _context.Products.Where(x => x.Id >= last && x.Id < last + 5).ToList();
public IEnumerable<Product> Get(int? lastId) {
if (!lastId.HasValue)
lastId = 1;
return _context.Products.Where(x => x.Id >= lastId && x.Id < lastId + 5).ToList();
}
}

View File

@ -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);
}
}
}