public ViewResult List(RidesGridDTO dto) { RidesGridBuilder builder = new RidesGridBuilder(dto); RideQueryOptions options = new RideQueryOptions() { Includes = "Motive, Car, Driver", PageNumber = builder.Route.PageNumber, PageSize = builder.Route.PageSize, OrderBy = ride => ride.Date, OrderByDirection = "desc" }; options.Filter(builder); IEnumerable <Ride> rides = _data.Rides.List(options); _helper.PopulateInitialMileage(rides); RideListViewModel model = new RideListViewModel { Rides = rides, Cars = _data.Cars.List(), Drivers = _data.Drivers.List(), Motives = _data.Motives.List(), TotalDistance = GetTotalDistance(builder), TotalCost = GetTotalCost(builder), CurrentRoute = builder.Route, TotalPages = builder.GetTotalPages(_data.Rides.Count) }; return(View(model)); }
private int?GetTotalDistance(RidesGridBuilder builder) { RideQueryOptions options = new RideQueryOptions(); options.Filter(builder); IEnumerable <Ride> rides = _data.Rides.List(options); _helper.PopulateInitialMileage(rides); int?distance = 0; foreach (Ride ride in rides) { distance += ride.GetDistance(); } return(distance); }
private double?GetTotalCost(RidesGridBuilder builder) { RideQueryOptions options = new RideQueryOptions(); options.Includes = "Car"; options.Filter(builder); IEnumerable <Ride> rides = _data.Rides.List(options); _helper.PopulateInitialMileage(rides); double?cost = 0; foreach (Ride ride in rides) { cost += ride.GetCost(); } return(cost); }