Skip to content

Commit

Permalink
clean up query
Browse files Browse the repository at this point in the history
  • Loading branch information
mlapaglia committed Jun 22, 2021
1 parent 116766d commit 6c3e969
Showing 1 changed file with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<SearchLicensePlateResponse> HandleAsync(
}
else
{
dbRequest = dbRequest.Where(x => x.PossibleNumbers.Contains(request.PlateNumber));
dbRequest = dbRequest.Where(x => x.PossibleNumbers.Contains(request.PlateNumber) || request.PlateNumber == x.BestNumber);
}
}

Expand All @@ -56,23 +56,13 @@ public async Task<SearchLicensePlateResponse> HandleAsync(
dbRequest = dbRequest.Where(x => x.ReceivedOnEpoch <= endEpochMilliseconds);
}

var platesToIgnore = await _processerContext.Ignores.ToListAsync(cancellationToken);
var platesToIgnore = (await _processerContext.Ignores
.Select(x => x.PlateNumber)
.ToListAsync(cancellationToken));

if (!request.FilterIgnoredPlates)
{
foreach (var plateToIgnore in platesToIgnore)
{
if (plateToIgnore.IsStrictMatch)
{
dbRequest = dbRequest.Where(x => plateToIgnore.PlateNumber != x.BestNumber);
}
else
{
dbRequest = dbRequest.Where(x =>
plateToIgnore.PlateNumber != x.BestNumber
|| !x.PossibleNumbers.Contains(plateToIgnore.PlateNumber));
}
}
dbRequest = dbRequest.Where(x => !platesToIgnore.Contains(x.PossibleNumbers) && !platesToIgnore.Contains(x.BestNumber));
}

if (!string.IsNullOrWhiteSpace(request.VehicleMake))
Expand Down Expand Up @@ -112,7 +102,7 @@ public async Task<SearchLicensePlateResponse> HandleAsync(
{
licensePlates.Add(PlateMapper.MapPlate(
plate,
platesToIgnore.Select(x => x.PlateNumber).ToList(),
platesToIgnore,
platesToAlert));
}

Expand Down

0 comments on commit 6c3e969

Please sign in to comment.