Changement dans la BD et les modèles
This commit is contained in:
		| @@ -29,7 +29,13 @@ public class ProductController : Controller { | ||||
|     } | ||||
|  | ||||
|     [HttpPost(Name = "Product")] | ||||
|     public void Post(Product prod) { | ||||
|     public void Post(string title, string description, decimal price, string imagename) { | ||||
|         Product prod = new() {  | ||||
|             Title =  title, | ||||
|             Description = description, | ||||
|             Price = price, | ||||
|             ImageName = imagename | ||||
|         }; | ||||
|         try { | ||||
|             _context.Products.Add(prod); | ||||
|         } catch (Exception e) { | ||||
| @@ -38,8 +44,49 @@ public class ProductController : Controller { | ||||
|     } | ||||
|  | ||||
|     [HttpPut(Name = "Product")] | ||||
|     public void Put(Product prod) { | ||||
|     public void Put(int id, string title, string description, decimal? price, string imagename) { | ||||
|         try { | ||||
|             Product prod = _context.Products.Where(x => x.Id == id).First(); | ||||
|  | ||||
|             if (title != null || title != "") | ||||
|                 prod.Title = title; | ||||
|  | ||||
|             if (description != null || description != "") | ||||
|                 prod.Description = description; | ||||
|  | ||||
|             if (price.HasValue || price > 0) | ||||
|                 prod.Price = (decimal)price; | ||||
|  | ||||
|             if (imagename != null || imagename != "") | ||||
|                 prod.ImageName = imagename; | ||||
|  | ||||
|             _context.Products.Update(prod); | ||||
|         } catch (Exception e) { | ||||
|             _logger.LogError(8, e.Message); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     [HttpPatch(Name = "Product")] | ||||
|     public void Patch(int id, string title, string description, decimal? price, string imagename) { | ||||
|         try { | ||||
|             Product prod = _context.Products.Where(x => x.Id == id).First(); | ||||
|  | ||||
|             if (title != null) | ||||
|                 prod.Title = title; | ||||
|             else prod.Title = ""; | ||||
|  | ||||
|             if (description != null) | ||||
|                 prod.Description = description; | ||||
|             else prod.Description = ""; | ||||
|  | ||||
|             if (price.HasValue || price > 0) | ||||
|                 prod.Price = (decimal)price; | ||||
|             else prod.Price = 0.01M; | ||||
|  | ||||
|             if (imagename != null) | ||||
|                 prod.ImageName = imagename; | ||||
|             else prod.ImageName = ""; | ||||
|  | ||||
|             _context.Products.Update(prod); | ||||
|         } catch (Exception e) { | ||||
|             _logger.LogError(8, e.Message); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user