Added order item updating
This commit is contained in:
@@ -146,6 +146,34 @@ public class OrderController : Controller
|
||||
return RedirectToAction("Details", new { code = orderItem.Order?.OrderCode });
|
||||
}
|
||||
|
||||
// POST: Order/UpdateItem
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> UpdateItem(int orderItemId, int quantity, string comments)
|
||||
{
|
||||
var orderItem = await _context.OrderItems
|
||||
.Include(oi => oi.Order)
|
||||
.Include(oi => oi.MenuItem)
|
||||
.FirstOrDefaultAsync(oi => oi.Id == orderItemId);
|
||||
|
||||
if (orderItem == null)
|
||||
return NotFound("Order item not found");
|
||||
|
||||
if (orderItem.Order?.IsClosed == true)
|
||||
return BadRequest("Cannot update items in a closed order");
|
||||
|
||||
if (orderItem.ParticipantEmail != User.Identity?.Name)
|
||||
return Forbid("Only the participant who added this item can update it");
|
||||
|
||||
orderItem.Quantity = quantity;
|
||||
orderItem.Comments = comments;
|
||||
|
||||
_context.OrderItems.Update(orderItem);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToAction("Details", new { code = orderItem.Order?.OrderCode });
|
||||
}
|
||||
|
||||
|
||||
// GET: Order/Details/{code}
|
||||
public async Task<IActionResult> Details(string code)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user