public async Task <List <Location> > RetrieveVehiclePositionWithRange(LocationRangeDTO locationRangeDTO) { if (locationRangeDTO == null) { throw new KeyNotFoundException("location Range paramters are empty"); } return(await _vehicleRepository.GetVehiclePositionRange(locationRangeDTO)); }
public async Task <ActionResult <Location> > GetVehicleCurrentPositionRange([FromQuery] LocationRangeDTO locationRangeDTO) { var currentLocationRange = await _vehicleService.RetrieveVehiclePositionWithRange(locationRangeDTO); if (currentLocationRange == null) { return(NotFound()); } return(Ok(currentLocationRange)); }
public async Task <List <Location> > GetVehiclePositionRange(LocationRangeDTO locationRangeDTO) { var filter = Builders <Vehicle> .Filter.And( Builders <Vehicle> .Filter.Where(x => x.Id == locationRangeDTO.VehicleId), Builders <Vehicle> .Filter.ElemMatch(x => x.Devices, d => d.Id == locationRangeDTO.DeviceId)); var vehicle = await _vehicles.Find(filter).FirstOrDefaultAsync(); var locations = vehicle.Devices.Select(c => c.Locations) .FirstOrDefault() .Where(c => c.UpdateLocationTimeStamp >= locationRangeDTO.StartDate && c.UpdateLocationTimeStamp <= locationRangeDTO.EndDate); return(locations.ToList()); }