public Task <ActionResult <IEnumerable <LocationModel> > > GetLocations([FromRoute] int assetId, [FromQuery] LocationHistoryRequestModel model) { return(HandleCommand <GetLocationsCommand, IEnumerable <LocationModel> >( new GetLocationsCommand { AssetId = assetId, Model = model, UserId = User.GetId() })); }
public async Task <List <LocationModel> > GetLocations(LocationHistoryRequestModel model) { IQueryable <LocationEntity> queryable = repository.GetEntities <LocationEntity>(); queryable = ApplyFiltering(queryable, model); queryable = queryable .OrderByDescending(x => x.DateTime) .Take(100000); List <LocationEntity> locations = await queryable.ToListAsync(); List <LocationModel> mapped = locations.Select(mapper.Map <LocationEntity, LocationModel>).ToList(); return(mapped); }
private static IQueryable <LocationEntity> ApplyFiltering(IQueryable <LocationEntity> queryable, LocationHistoryRequestModel model) { queryable = queryable.Where(x => x.AssetId == model.AssetId); queryable = queryable.Where(x => x.DateTime > model.StartDate && x.DateTime < model.EndDate); if (model.Latitude.HasValue && model.Longitude.HasValue && model.Radius.HasValue) { // TODO add location filter } if (model.StartSpeed.HasValue && model.EndSpeed.HasValue) { queryable = queryable.Where(x => x.Speed >= model.StartSpeed && x.Speed <= model.EndSpeed); } else if (model.StartSpeed.HasValue) { queryable = queryable.Where(x => x.Speed >= model.StartSpeed); } else if (model.EndSpeed.HasValue) { queryable = queryable.Where(x => x.Speed <= model.EndSpeed); } if (model.StartAltitude.HasValue && model.EndAltitude.HasValue) { queryable = queryable.Where(x => x.Altitude >= model.StartAltitude && x.Altitude <= model.EndAltitude); } else if (model.StartAltitude.HasValue) { queryable = queryable.Where(x => x.Altitude >= model.StartAltitude); } else if (model.EndAltitude.HasValue) { queryable = queryable.Where(x => x.Altitude <= model.EndAltitude); } return(queryable); }
public async Task <List <LocationModel> > GetHistory([FromQuery] LocationHistoryRequestModel model) { List <LocationModel> locations = await locationService.GetLocations(model); return(locations); }