Woohoo
This commit is contained in:
@@ -37,18 +37,18 @@ public class ProductController : Controller {
|
||||
Description = description,
|
||||
Price = price.HasValue? (decimal)price: 0.01M,
|
||||
Quantity = quantity.HasValue ? (uint)quantity : 0,
|
||||
isDiscontinued = disc.HasValue? (bool)disc: false,
|
||||
ImageName = imagename
|
||||
};
|
||||
try {
|
||||
_context.Products.Add(prod);
|
||||
_context.SaveChanges();
|
||||
} catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut(Name = "Product")]
|
||||
public void Put(int id, string title, string category, string description, decimal? price, uint? quantity, bool? disc, string imagename) {
|
||||
public void Put(int id, string title, string category, string description, decimal? price, uint? quantity, string? status, string imagename) {
|
||||
try {
|
||||
Product prod = _context.Products.Where(x => x.Id == id).First();
|
||||
|
||||
@@ -67,20 +67,37 @@ public class ProductController : Controller {
|
||||
if (quantity.HasValue)
|
||||
prod.Quantity = (uint)quantity;
|
||||
|
||||
if (disc.HasValue)
|
||||
prod.isDiscontinued = (bool)disc;
|
||||
switch (status) {
|
||||
case "isAvailable":
|
||||
prod.Status = Product.States.Available;
|
||||
break;
|
||||
case "isUnavailable":
|
||||
prod.Status = Product.States.Unavailable;
|
||||
break;
|
||||
case "isBackOrder":
|
||||
prod.Status = Product.States.BackOrder;
|
||||
break; ;
|
||||
case "isClearance":
|
||||
prod.Status = Product.States.Clearance;
|
||||
break;
|
||||
case "isDiscontinued":
|
||||
prod.Status = Product.States.Discontinued;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (imagename != null || imagename != "")
|
||||
prod.ImageName = imagename;
|
||||
|
||||
_context.Products.Update(prod);
|
||||
_context.SaveChanges();
|
||||
} catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPatch(Name = "Product")]
|
||||
public void Patch(int id, string title, string category, string description, decimal? price, uint? quantity, bool? disc, string imagename) {
|
||||
public void Patch(int id, string title, string category, string description, decimal? price, uint? quantity, string? status, string imagename) {
|
||||
try {
|
||||
Product prod = _context.Products.Where(x => x.Id == id).First();
|
||||
|
||||
@@ -104,15 +121,33 @@ public class ProductController : Controller {
|
||||
prod.Quantity = (uint)quantity;
|
||||
else prod.Quantity = 0;
|
||||
|
||||
if (disc.HasValue)
|
||||
prod.isDiscontinued = (bool)disc;
|
||||
else prod.isDiscontinued = false;
|
||||
switch (status) {
|
||||
case "isAvailable":
|
||||
prod.Status = Product.States.Available;
|
||||
break;
|
||||
case "isUnavailable":
|
||||
prod.Status = Product.States.Unavailable;
|
||||
break;
|
||||
case "isBackOrder":
|
||||
prod.Status = Product.States.BackOrder;
|
||||
break; ;
|
||||
case "isClearance":
|
||||
prod.Status = Product.States.Clearance;
|
||||
break;
|
||||
case "isDiscontinued":
|
||||
prod.Status = Product.States.Discontinued;
|
||||
break;
|
||||
default:
|
||||
prod.Status = prod.Quantity > 0 ? Product.States.Available : Product.States.Unavailable;
|
||||
break;
|
||||
}
|
||||
|
||||
if (imagename != null)
|
||||
prod.ImageName = imagename;
|
||||
else prod.ImageName = "";
|
||||
|
||||
_context.Products.Update(prod);
|
||||
_context.SaveChanges();
|
||||
} catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
}
|
||||
|
Reference in New Issue
Block a user