public async Task<List<Tool>> GetToolsAsync(GetToolParams criteria)
{
IQueryable<Tool> tools = this.dbContext.Tools
.Include(t => t.Type)
.Include(t => t.ToolStatus)
.Include(t => t.AssignedUsers)
.Include(t => t.Tag)
.Include(t => t.Inspections)
.Include(t => t.Groups)
.ThenInclude(g => g.Group)
/*.Include(t => t.Sites)
.ThenInclude(s => s.Site)*/;
if (criteria.Latitude != null && criteria.Longitude != null && criteria.Distance != null)
{
IGeometryFactory geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
IPoint point = geometryFactory.CreatePoint(new Coordinate(criteria.Longitude.Value, criteria.Latitude.Value));
Polygon surrounding = (Polygon)geometryFactory.CreatePolygon(point.Buffer(criteria.Distance.Value).Coordinates);
if (!surrounding.Shell.IsCCW)
{
surrounding = (Polygon)geometryFactory.CreatePolygon(surrounding.Shell.Reverse().Coordinates);
}
tools = tools.Where(t => t.CurrentPosition != null && (t.CurrentPosition.Intersects(surrounding) ? true : false));
}
// Other where clauses goes here. I removed them because they're irrelevant to this problem
List<Tool> toolsList = await tools.ToListAsync();
return toolsList;
}