Added order item updating

This commit is contained in:
2025-11-30 19:37:34 +01:00
parent 034a8c2c66
commit 428ebc2e3f
2 changed files with 65 additions and 1 deletions

View File

@@ -146,6 +146,34 @@ public class OrderController : Controller
return RedirectToAction("Details", new { code = orderItem.Order?.OrderCode }); 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} // GET: Order/Details/{code}
public async Task<IActionResult> Details(string code) public async Task<IActionResult> Details(string code)
{ {

View File

@@ -127,6 +127,42 @@
<input type="hidden" name="orderItemId" value="@orderItem.Id" /> <input type="hidden" name="orderItemId" value="@orderItem.Id" />
<button type="submit" class="btn btn-sm btn-danger">@Localizer.Get("Delete")</button> <button type="submit" class="btn btn-sm btn-danger">@Localizer.Get("Delete")</button>
</form> </form>
<button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#updateModal-@orderItem.Id">@Localizer.Get("Edit")</button>
<!-- Update Modal for Order Item -->
<div class="modal fade" id="updateModal-@orderItem.Id" tabindex="-1" aria-labelledby="updateModalLabel-@orderItem.Id" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="updateModalLabel-@orderItem.Id">@Localizer.Get("EditOrderItem")</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="post" action="/order/updateitem">
<div class="modal-body">
<input type="hidden" name="orderItemId" value="@orderItem.Id" />
<div class="mb-3">
<label class="form-label">@Localizer.Get("Item")</label>
<input type="text" class="form-control" value="@orderItem.MenuItem?.Name" readonly disabled>
</div>
<div class="mb-3">
<label class="form-label">@Localizer.Get("Qty")</label>
<input type="number" name="quantity" class="form-control" value="@orderItem.Quantity" min="1" required>
</div>
<div class="mb-3">
<label class="form-label">@Localizer.Get("Comments")</label>
<textarea name="comments" class="form-control" rows="3">@orderItem.Comments</textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">@Localizer.Get("Cancel")</button>
<button type="submit" class="btn btn-primary">@Localizer.Get("Update")</button>
</div>
</form>
</div>
</div>
</div>
} }
</td> </td>
</tr> </tr>