I am trying to search for an empty time slot searching multiple customers by slot number. If the time is available for that customer it should return the first customer found.
Sample data (Each customer has a unique slot number)
customer 1: slotnumber 0, time 0
customer 1: slotnumber 0, time 1
customer 1: slotnumber 0, time 2
customer 1: slotnumber 0, time 4
customer 2: slotnumber 1, time 0
customer 2: slotnumber 1, time 1
I have the following class:
public class CustomerSlot
{
public int customerid { get; set; }
public int slotnumber { get; set; }
public int time { get; set; }
}
Then I have a list of customersslots:
List<CustomerSlot> lstCustomerSlots = new List<CustomerSlot>();
Now lets say I want to find the first slot with time 3 available using the above data.
This is where i need help. I dont quite have the correct syntax to group by the customer and return a customer that has that time slot available:
CustomerSlot timeSpaceFound = lstCustomerSlots
.Where(t => t.time != 3) // Search for time 3
.GroupBy(c => c.customerid) // Search an entire customer
.OrderBy(c => c.customerid) // Start searching by the order of first customerid
.FirstOrDefault();
Any help setting up the above lambda would be appreciated. Have not found any examples searching for a solution online. Thank you.