Continuage d'API

This commit is contained in:
MarcEricMartel
2022-10-09 12:07:35 -07:00
parent f5351340d8
commit 1f7c97949d
7 changed files with 117 additions and 19 deletions

View File

@@ -29,11 +29,14 @@ public class ProductController : Controller {
}
[HttpPost(Name = "Product")]
public void Post(string title, string description, decimal price, string imagename) {
public void Post(int id, string title, string category, string description, decimal? price, uint? quantity, bool? disc, string imagename) {
Product prod = new() {
Title = title,
Category = category,
Description = description,
Price = price,
Price = price.HasValue? (decimal)price: 0.01M,
Quantity = quantity.HasValue ? (uint)quantity : 0,
isDiscontinued = disc.HasValue? (bool)disc: false,
ImageName = imagename
};
try {
@@ -44,19 +47,28 @@ public class ProductController : Controller {
}
[HttpPut(Name = "Product")]
public void Put(int id, string title, string description, decimal? price, string imagename) {
public void Put(int id, string title, string category, string description, decimal? price, uint? quantity, bool? disc, string imagename) {
try {
Product prod = _context.Products.Where(x => x.Id == id).First();
if (title != null || title != "")
prod.Title = title;
if (category != null || category != "")
prod.Category = category;
if (description != null || description != "")
prod.Description = description;
if (price.HasValue || price > 0)
prod.Price = (decimal)price;
if (quantity.HasValue)
prod.Quantity = (uint)quantity;
if (disc.HasValue)
prod.isDiscontinued = (bool)disc;
if (imagename != null || imagename != "")
prod.ImageName = imagename;
@@ -67,7 +79,7 @@ public class ProductController : Controller {
}
[HttpPatch(Name = "Product")]
public void Patch(int id, string title, string description, decimal? price, string imagename) {
public void Patch(int id, string title, string category, string description, decimal? price, uint? quantity, bool? disc, string imagename) {
try {
Product prod = _context.Products.Where(x => x.Id == id).First();
@@ -75,6 +87,10 @@ public class ProductController : Controller {
prod.Title = title;
else prod.Title = "";
if (category != null)
prod.Category = category;
else prod.Category = "";
if (description != null)
prod.Description = description;
else prod.Description = "";
@@ -83,6 +99,14 @@ public class ProductController : Controller {
prod.Price = (decimal)price;
else prod.Price = 0.01M;
if (quantity.HasValue)
prod.Quantity = (uint)quantity;
else prod.Quantity = 0;
if (disc.HasValue)
prod.isDiscontinued = (bool)disc;
else prod.isDiscontinued = false;
if (imagename != null)
prod.ImageName = imagename;
else prod.ImageName = "";