Untitled
Anonymous
plain_text
02/29/2024 6:23 AM
748 B
17
Indexable
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
}
Editor is loading...
Leave a Comment