From 428ebc2e3fc0520f511e1fa4011143a470233d2a Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Sun, 30 Nov 2025 19:37:34 +0100 Subject: [PATCH] Added order item updating --- Controllers/OrderController.cs | 28 +++++++++++++++++++++++++ Views/Order/Details.cshtml | 38 +++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Controllers/OrderController.cs b/Controllers/OrderController.cs index 36190bb..b495e8c 100644 --- a/Controllers/OrderController.cs +++ b/Controllers/OrderController.cs @@ -146,6 +146,34 @@ public class OrderController : Controller return RedirectToAction("Details", new { code = orderItem.Order?.OrderCode }); } + // POST: Order/UpdateItem + [HttpPost] + public async Task 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 Details(string code) { diff --git a/Views/Order/Details.cshtml b/Views/Order/Details.cshtml index a3b5d25..04833ea 100644 --- a/Views/Order/Details.cshtml +++ b/Views/Order/Details.cshtml @@ -126,7 +126,43 @@
-
+ + + + }