Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
501 B
2
Indexable
Never
public async Task<IActionResult> DeleteAllProductsFromCart(string email)
    {
        var cartsToDelete = await _context.Carts.Where(c => c.EmailId == email).ToListAsync();

        if (cartsToDelete == null || !cartsToDelete.Any())
        {
            return NotFound(); // Return 404 if no carts are found
        }

        _context.Carts.RemoveRange(cartsToDelete);
        await _context.SaveChangesAsync();

        return Ok(cartsToDelete); // Return 200 with the list of deleted carts
    }
Leave a Comment