L'importation d'image fonctionne. Il manque à faire fonctionner la modifiction et le delete avec.

This commit is contained in:
Victor Turgeon
2022-11-01 18:50:32 -04:00
parent f38f4bf44a
commit 9df28d3eed
47 changed files with 198 additions and 34 deletions

View File

@@ -9,10 +9,10 @@ using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Cors;
using GrossesMitainesAPI.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Hosting;
#endregion
[EnableCors("_myAllowSpecificOrigins"), ApiController, Route("api/[controller]"),
[EnableCors("_myAllowSpecificOrigins"), ApiController, Route("api/[controller]"),
Authorize(AuthenticationSchemes = "Identity.Application")]
public class InventoryController : Controller {
#region Constants
@@ -24,14 +24,16 @@ public class InventoryController : Controller {
private readonly ILogger<InventoryController> _logger;
private readonly InventoryContext _context;
private readonly DatabaseCacheService _cache;
private readonly IWebHostEnvironment _hostEnvironment;
#endregion
#region Ctor
public InventoryController(ILogger<InventoryController> logger, InventoryContext context, DatabaseCacheService cache) {
public InventoryController(ILogger<InventoryController> logger, InventoryContext context, DatabaseCacheService cache, IWebHostEnvironment hostEnvironment) {
_context = context;
_logger = logger;
_cache = cache;
_hostEnvironment = hostEnvironment;
}
#endregion
@@ -41,7 +43,7 @@ public class InventoryController : Controller {
public IEnumerable<ProductViewModel> Get(int? lastId, string? order, string? filterPrice, string? filterState, bool? all) {
bool iscache = false;
IQueryable<ProductViewModel> ret;
if (_cache.isOk()) {
if (_cache.isOk()) {
ret = _cache.queryCache().Select(x => new ProductViewModel(x));
iscache = true;
}
@@ -78,20 +80,20 @@ public class InventoryController : Controller {
ret = ret.Where(x => x.Status == ProductModel.States.Discontinued);
break;
case "isPromoted":
ret = ret.Where(x => x.Status == ProductModel.States.Clearance ||
ret = ret.Where(x => x.Status == ProductModel.States.Clearance ||
x.Status == ProductModel.States.Promotion);
break;
default: break;
}
switch (order) {
case "Price":
ret = ret.OrderBy(x => x.Status == ProductModel.States.Promotion ||
x.Status == ProductModel.States.Clearance ?
ret = ret.OrderBy(x => x.Status == ProductModel.States.Promotion ||
x.Status == ProductModel.States.Clearance ?
x.PromoPrice : x.Price);
break;
case "PriceDesc":
ret = ret.OrderByDescending(x => x.Status == ProductModel.States.Promotion ||
x.Status == ProductModel.States.Clearance ?
ret = ret.OrderByDescending(x => x.Status == ProductModel.States.Promotion ||
x.Status == ProductModel.States.Clearance ?
x.PromoPrice : x.Price);
break;
case "Title":
@@ -114,9 +116,10 @@ public class InventoryController : Controller {
try {
if (!lastId.HasValue || lastId == 0)
yup = true;
foreach (ProductViewModel prod in ret.ToList()) {
if (yup && add < AMOUNT_SCROLL || (all.HasValue && all == true)) {
lst.Add(prod);
add++;
}
@@ -124,13 +127,15 @@ public class InventoryController : Controller {
yup = true;
}
return lst;
} catch (Exception e) {
}
catch (Exception e) {
if (iscache)
_logger.LogError(e, "Erreur d'appel de cache.");
else _logger.LogError(e, "Erreur d'appel d'API.");
return new List<ProductViewModel>();
}
}
// Inventory/Delete => Décrémenter un produit. Va aller chercher directement dans la BD.
//[EnableCors("_myAllowSpecificOrigins"), HttpDelete(Name = "Inventory"), AllowAnonymous]
//public ActionResult<int> Delete(int? id) {