Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
461 B
2
Indexable
Never
public async Task<List<Cart>> DeleteAllProductsFromCart(string email)
{
    List<Cart> cartsToDelete = await _context.Carts.Where(c => c.EmailId == email).ToListAsync();
    
    if (cartsToDelete != null && cartsToDelete.Any())
    {
        foreach (var cart in cartsToDelete)
        {
            _context.Carts.Remove(cart);
        }
        
        await _context.SaveChangesAsync();
        
        return cartsToDelete;
    }
    
    return null;
}
Leave a Comment