react-version #1

Merged
memartel_loc merged 290 commits from react-version into main 2023-11-04 09:48:15 -04:00
2 changed files with 42 additions and 23 deletions
Showing only changes of commit 9de1611b5a - Show all commits

View File

@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging;
namespace GrossesMitainesAPI.Controllers;
[ApiController, Route("[controller]")]
[ApiController, Route("api/[controller]")]
public class InventoryController : Controller {
private readonly ILogger<InventoryController> _logger;
private readonly InventoryContext _context;
@ -22,27 +22,5 @@ public class InventoryController : Controller {
last = 1;
return _context.Products.Where(x => x.Id >= last && x.Id < last + 5).ToList();
}
[HttpGet(Name = "Product")]
public Product Get(int id) {
Product prod;
try {
prod = _context.Products.Where(x => x.Id == id).First();
} catch (Exception e) {
_logger.LogError(8, e.Message);
prod = new Product();
}
return prod;
}
[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);
}
}
}

View File

@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Mvc;
using GrossesMitainesAPI.Models;
using System.Linq;
using GrossesMitainesAPI.Data;
using Microsoft.Extensions.Logging;
namespace GrossesMitainesAPI.Controllers;
[ApiController, Route("api/[controller]")]
public class ProductController : Controller {
private readonly ILogger<ProductController> _logger;
private readonly InventoryContext _context;
public ProductController(ILogger<ProductController> logger, InventoryContext context) {
_logger = logger;
_context = context;
}
[HttpGet(Name = "Product")]
public Product Get(int id) {
Product prod;
try {
prod = _context.Products.Where(x => x.Id == id).First();
} catch (Exception e) {
_logger.LogError(8, e.Message);
prod = new Product();
}
return prod;
}
[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);
}
}
}