Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
560 B
1
Indexable
Never
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

public async Task<List<Cart>> DeleteAllProductsFromCart(string email)
{
    var cartsToDelete = await _context.Carts.Where(c => c.EmailId == email).ToListAsync();

    if (cartsToDelete == null || !cartsToDelete.Any())
    {
        return null; // Return null or throw an exception if no carts are found
    }

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

    return cartsToDelete; // Return the list of carts that were deleted
}
Leave a Comment