public Table GetFreeTable(int businessID, int peopleAmount, DateTime reservationDate) { // Get tables with enough seats for businessID and put table with least amount of seats first var qry = from t in GetTables(businessID).Data where t.Seats >= peopleAmount select t; // Get tables that are free at day/time qry = from t in qry where _reservationManager.DoesReservationExistForTable(t.ID, reservationDate) == false orderby t.Seats ascending select t; // Return free table with least amount of seats if (qry.Count() > 0) { return(qry.First()); } return(null); }