Added Bestellzustände
This commit is contained in:
@@ -94,15 +94,15 @@ public class OrderController : Controller
|
||||
if (order == null)
|
||||
return NotFound("Order not found");
|
||||
|
||||
if (order.IsClosed)
|
||||
return BadRequest("This order is closed");
|
||||
if (order.IsClosed || order.IsCompleted)
|
||||
return BadRequest("This order cannot be joined");
|
||||
|
||||
return View(order);
|
||||
}
|
||||
|
||||
// POST: Order/AddItem
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AddItem(int orderId, int menuItemId, int quantity, string participantName, string? participantEmail)
|
||||
public async Task<IActionResult> AddItem(int orderId, int menuItemId, int quantity)
|
||||
{
|
||||
var order = await _context.Orders.FindAsync(orderId);
|
||||
if (order == null || order.IsClosed)
|
||||
@@ -117,8 +117,8 @@ public class OrderController : Controller
|
||||
OrderId = orderId,
|
||||
MenuItemId = menuItemId,
|
||||
Quantity = quantity,
|
||||
ParticipantName = participantName,
|
||||
ParticipantEmail = participantEmail
|
||||
ParticipantName = User.Identity?.Name ?? "",
|
||||
ParticipantEmail = User.Identity?.Name
|
||||
};
|
||||
|
||||
_context.OrderItems.Add(orderItem);
|
||||
@@ -152,6 +152,9 @@ public class OrderController : Controller
|
||||
if (order.IsClosed)
|
||||
return BadRequest("Order is already closed");
|
||||
|
||||
if (order.CreatorName != User.Identity?.Name)
|
||||
return Forbid("Only the order creator can close this order");
|
||||
|
||||
order.IsClosed = true;
|
||||
order.ClosedAt = DateTime.UtcNow;
|
||||
|
||||
@@ -161,6 +164,33 @@ public class OrderController : Controller
|
||||
return RedirectToAction("Details", new { code = order.OrderCode });
|
||||
}
|
||||
|
||||
// GET: Order/Complete/{code}
|
||||
public async Task<IActionResult> Complete(string code)
|
||||
{
|
||||
var order = await _context.Orders.FirstOrDefaultAsync(o => o.OrderCode == code);
|
||||
|
||||
if (order == null)
|
||||
return NotFound("Order not found");
|
||||
|
||||
// Only the creator can complete an order
|
||||
if (order.CreatorName != User.Identity?.Name)
|
||||
return Forbid("Only the order creator can mark this as completed");
|
||||
|
||||
if (!order.IsClosed)
|
||||
return BadRequest("Order must be closed before marking as completed");
|
||||
|
||||
if (order.IsCompleted)
|
||||
return BadRequest("Order is already marked as completed");
|
||||
|
||||
order.IsCompleted = true;
|
||||
order.CompletedAt = DateTime.UtcNow;
|
||||
|
||||
_context.Orders.Update(order);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToAction("Details", new { code = order.OrderCode });
|
||||
}
|
||||
|
||||
private string GenerateOrderCode()
|
||||
{
|
||||
return Guid.NewGuid().ToString().Substring(0, 8).ToUpper();
|
||||
|
||||
Reference in New Issue
Block a user