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]")] [ApiController, Route("api/[controller]")]
public class InventoryController : Controller { public class InventoryController : Controller {
private readonly ILogger<InventoryController> _logger;
private readonly InventoryContext _context; private readonly InventoryContext _context;
public InventoryController(ILogger<InventoryController> logger, InventoryContext context) { public InventoryController(InventoryContext context) {
_logger = logger;
_context = context; _context = context;
} }
[HttpGet(Name ="Inventory")] [HttpGet(Name ="Inventory")]
public IEnumerable<Product> Get(int? last) { public IEnumerable<Product> Get(int? lastId) {
if (!last.HasValue) if (!lastId.HasValue)
last = 1; lastId = 1;
return _context.Products.Where(x => x.Id >= last && x.Id < last + 5).ToList(); 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")] [HttpPost(Name = "Product")]
public void Post(Product prod) { public void Post(Product prod) {
prod.Id = _context.Products.Count();
try { try {
_context.Products.Add(prod); _context.Products.Add(prod);
} catch (Exception e) { } catch (Exception e) {
_logger.LogError(8, e.Message); _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);
}
}
} }