HELL YE- ...oh.
This commit is contained in:
parent
ccb8fa941d
commit
8068f6965d
@ -9,7 +9,13 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using GrossesMitainesAPI.Services;
|
using GrossesMitainesAPI.Services;
|
||||||
|
|
||||||
namespace GrossesMitainesAPI.Controllers;
|
namespace GrossesMitainesAPI.Controllers;
|
||||||
|
/// <summary>
|
||||||
|
/// Ce contrôleur ne va pas chercher dans la cache,
|
||||||
|
/// mais les changements dans celui-ci entrainera
|
||||||
|
/// une demande de mise à jour dans cette dernière
|
||||||
|
/// qui sera effectuée dans les 10 secondes après
|
||||||
|
/// l'éxécution d'une modification de la BD.
|
||||||
|
/// </summary>
|
||||||
[EnableCors("_myAllowSpecificOrigins")]
|
[EnableCors("_myAllowSpecificOrigins")]
|
||||||
[ApiController, Route("api/[controller]")]
|
[ApiController, Route("api/[controller]")]
|
||||||
public class ProductController : ControllerBase {
|
public class ProductController : ControllerBase {
|
||||||
@ -40,20 +46,17 @@ public class ProductController : ControllerBase {
|
|||||||
[EnableCors("_myAllowSpecificOrigins")]
|
[EnableCors("_myAllowSpecificOrigins")]
|
||||||
[HttpPost(Name = "Product")]
|
[HttpPost(Name = "Product")]
|
||||||
public ActionResult<Product> Post(Product prod) {
|
public ActionResult<Product> Post(Product prod) {
|
||||||
|
|
||||||
if (prod.Price <= prod.PromoPrice)
|
if (prod.Price <= prod.PromoPrice)
|
||||||
prod.PromoPrice = prod.Price - 0.01M;
|
prod.PromoPrice = prod.Price - 0.01M;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_context.Products.Add(prod);
|
_context.Products.Add(prod);
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
_cache.askForRefresh();
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
_logger.LogError(8, e.Message);
|
_logger.LogError(8, e.Message);
|
||||||
return BadRequest(e.Message);
|
return BadRequest(e.Message);
|
||||||
}
|
}
|
||||||
|
_cache.askForRefresh();
|
||||||
return prod;
|
return prod;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,13 +66,12 @@ public class ProductController : ControllerBase {
|
|||||||
try {
|
try {
|
||||||
_context.Products.Update(prod);
|
_context.Products.Update(prod);
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
_cache.askForRefresh();
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
_logger.LogError(8, e.Message);
|
_logger.LogError(8, e.Message);
|
||||||
return BadRequest(e.Message);
|
return BadRequest(e.Message);
|
||||||
}
|
}
|
||||||
|
_cache.askForRefresh();
|
||||||
return prod;
|
return prod;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,13 +81,12 @@ public class ProductController : ControllerBase {
|
|||||||
try {
|
try {
|
||||||
_context.Products.Remove(_context.Products.Where(x => x.Id == id).First());
|
_context.Products.Remove(_context.Products.Where(x => x.Id == id).First());
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
_cache.askForRefresh();
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
_logger.LogError(8, e.Message);
|
_logger.LogError(8, e.Message);
|
||||||
return BadRequest(e.Message);
|
return BadRequest(e.Message);
|
||||||
}
|
}
|
||||||
|
_cache.askForRefresh();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user