public IEnumerable <DriverTripSummary> GetDriverTripSummaries() { var nonzeroSummaries = AllTrips.GroupBy(t => t.DriverName).Select(g => new DriverTripSummary() { DriverName = g.Key, TotalDistance = g.Sum(t => t.MilesDriven), TotalMinutes = Convert.ToInt32(g.Sum(t => bs.GetMinutesElapsed(t))) // convert the sum rather than each item }); //This is a little strange because strings aren't unique; would be much better to do this with Ids. See comment in Driver class var usersWithNoTrips = AllRegisteredDrivers.Select(x => x.Name).Except(nonzeroSummaries.Select(y => y.DriverName)); var summariesForUsersWithNoTrips = usersWithNoTrips.Select(u => new DriverTripSummary() { DriverName = u // other fields will default to 0 }); return(nonzeroSummaries.Concat(summariesForUsersWithNoTrips)); }
/// <summary> /// This actually persists the driver in the database. /// </summary> /// <param name="d">A vetted, bona fide new driver</param> private void ActuallyRegisterDriver(Driver d) { AllRegisteredDrivers.Add(d); }