コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }