in FMLab/DriversLicenseChecker.cs [15:52]
public static bool CheckDriversLicense(long customerId)
{
// Use LINQ to get back to the information about the
// license number
FMCustomer customer;
QueryProvider provider = new AXQueryProvider(null);
var customers = new QueryCollection<FMCustomer>(provider);
// Build the query (but do not execute it)
var query = from c in customers
where c.RecId == customerId
select c;
// Execute the query:
customer = query.FirstOrDefault();
if (customer == null)
{
throw new ArgumentException
("The customerId does not designate a customer");
}
// or, much more succinctly:
// customer = customers.Single(c => c.RecId == customerId);
if (string.IsNullOrEmpty(customer.DriverLicense))
{
// No driver's license was recorded. Veto the rental.
return false;
}
// Call the DOT web service to validate the license number.
// This is not practical for this lab, because all the service providers
// charge for this service. Instead, just assume that any license number
// that contains the sequence "89" is valid.
// In the demo data, this is true for Adrian Lannin,
// but not for Phil Spencer.
return customer.DriverLicense.Contains("89");
}