I have some product items in a cart. A customer has already placed an order for ONE of the items in his cart, in the past.
I am trying to get a list of orders he has placed in the past (accomplished by GetOrders
).
Pass in the items in his cart to my method (pass in *items *in my method)
Check if any of the cart items match the orderItems
`public bool ProductFound(IReadOnlyCollection items)
{
var orders = GetOrders();
foreach (var order in orders)
{
if (items.Intersect(order.OrderItems).Any())
{
return true;
}
}
return false;
}`
I produce the above code but even though i know there is the same product in orderItems and items it never returns true. I then tried order.OrderItems.ProductId
to match the Id but then i had a cast error.
How could i check if one list contains any items in a second list passed in?
I visited this link for reference https://code-maze.com/csharp-check-if-items-of-a-list-exist-in-another-list/#:~:text=We%20can%20use%20the%20IEnumerable,()%20vs%20Count()%20in%20.