public IEnumerable <View.CarLogBySession> GetLogBySession(string carValueId, CarLogGetBinding binding)
 {
     using (var context = GetMainContext())
     {
         return(context.Cars.WhereUser(UserId)
                .Include(x => x.CarLogs)
                .SingleOrDefault(x => x.ValueId == carValueId)
                .CarLogs
                .AsQueryable()
                .Where(binding)
                .Where(x => !string.IsNullOrEmpty(x.Session))
                .GroupBy(x => x.Session)
                .Select(x => new View.CarLogBySession()
         {
             Count = x.Count(),
             Distance = x.Max(y => y.TripDistance),
             End = x.Max(y => y.Timestamp),
             FuelUsed = x.Max(y => y.FuelUsed),
             MaxEngineRpm = x.Max(y => y.EngineRpm),
             MaxSpeed = x.Max(y => y.SpeedKmh),
             Session = x.Key,
             Start = x.Min(y => y.Timestamp)
         })
                .OrderByDescending(x => x.End));
     }
 }
 public View.CarLog GetLatestLog(CarLogGetBinding binding)
 {
     using (var context = GetMainContext())
     {
         string carValueId = context.Users.Include(x => x.DefaultCar).SingleOrDefault(x => x.Id == UserId).DefaultCar.ValueId;
         return(GetLatestLog(carValueId, binding));
     }
 }
        public async Task <IEnumerable <View.CarLog> > GetLogs(string carValueId, CarLogGetBinding binding)
        {
            using (var context = GetMainContext())
            {
                int?carId = context.Cars.GetId(carValueId);

                return(await context.CarLogs
                       .Where(x => x.CarId == carId.Value)
                       .Where(binding)
                       .OrderBy(x => x.Timestamp)
                       .Select(x => new View.CarLog(x))
                       .ToListAsync());
            }
        }
        public View.CarLog GetLatestLog(string carValueId, CarLogGetBinding binding)
        {
            using (var db = GetMainContext())
            {
                int?carId = db.Cars.GetId(carValueId);

                //TODO: check if car belongs to user

                var carLog = db.CarLogs
                             .Where(x => x.CarId == carId)
                             .WhereIf(binding.HasOdometer.HasValue, x => x.Odometer.HasValue == binding.HasOdometer.Value)
                             .OrderByDescending(x => x.Timestamp)
                             .FirstOrDefault();

                return(carLog == null ? null : new View.CarLog(carLog));
            }
        }
示例#5
0
 public static IQueryable <CarLog> Where(this IQueryable <CarLog> logs, CarLogGetBinding binding)
 {
     return(logs.WhereTimestampInclusive(binding)
            .WhereIf(binding.HasOdometer.HasValue, x => binding.HasOdometer.HasValue == x.Odometer.HasValue));
 }
示例#6
0
 public async Task <IActionResult> GetLogs(string carId, [FromQuery] CarLogGetBinding binding) => Ok(await _carHandler.GetLogs(carId, binding));
示例#7
0
 public View.CarLog GetLogLatest(string carId, [FromQuery] CarLogGetBinding binding) => _carHandler.GetLatestLog(carId, binding);
示例#8
0
 public IEnumerable <View.CarLogBySession> GetLogBySession(string carId, [FromQuery] CarLogGetBinding binding) => _carHandler.GetLogBySession(carId, binding);