-
-
Save dcomartin/97747a69ba44c1610d48e3736828a1ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SwaggerOperation( | |
OperationId = "AvailableForSale", | |
Tags = new[] { "Sales" })] | |
[HttpPost("/sales/products/{sku}/availableForSale")] | |
public async Task<IActionResult> AvailableForSale([FromRoute] string sku) | |
{ | |
var product = await _db.Products.SingleOrDefaultAsync(x => x.Sku == sku); | |
if (product == null) | |
{ | |
return NotFound(); | |
} | |
if (product.ForSale) | |
{ | |
return Problem( | |
"Product is already Available For Sale.", | |
$"/sales/products/{sku}/availableForSale", | |
400, | |
"Cannot set product as available.", | |
"http://example.com/problems/already-available"); | |
} | |
if (product.QuantityOnHand <= 0) | |
{ | |
return Problem( | |
"Product has no Quantity on Hand.", | |
$"/sales/products/{sku}/availableForSale", | |
400, "Cannot set product as available.", | |
"http://example.com/problems/no-quantity"); | |
} | |
product.ForSale = true; | |
await _db.SaveChangesAsync(); | |
return Created(_urlHelper.Action("GetSalesProduct", "GetSalesProduct", new { sku }), null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment