Added order item delete functionality
This commit is contained in:
@@ -128,6 +128,24 @@ public class OrderController : Controller
|
||||
return RedirectToAction("Join", new { code = order.OrderCode });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> DeleteItem(int orderItemId)
|
||||
{
|
||||
var orderItem = await _context.OrderItems
|
||||
.Include(oi => oi.Order)
|
||||
.FirstOrDefaultAsync(oi => oi.Id == orderItemId);
|
||||
if (orderItem == null)
|
||||
return NotFound("Order item not found");
|
||||
|
||||
if (orderItem.Order?.CreatorName != User.Identity?.Name && orderItem.ParticipantEmail != User.Identity?.Name)
|
||||
return Forbid("Only the order creator or the participant who added the item can delete it");
|
||||
|
||||
_context.OrderItems.Remove(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