❔ Route returning multiple of the same item.

So, I am trying to query multiple cases with the same name and for some reason it return the correct amount of cases but instead of them actually being the different cases it returns the correct number of cases but they are all the first case out of the list. If anyone can shed some light on this issue it would be greatly appreciated.
// GET: api/SearchScreenViews/5
[HttpGet("{id}")]
public async Task<ActionResult<IEnumerable<SearchScreenView>>> GetSearchScreenView(string id)
{
if (string.IsNullOrEmpty(id))
{
return NotFound();
}

DateTime.TryParse(id, out DateTime parsedDate); // Parse input string to DateTime

var searchScreenViews = await _context.SearchScreens
.Where(p =>
(p.LastName != null && p.LastName.Contains(id)) ||
(p.FirstName != null && p.FirstName.Contains(id)) ||
(p.CitationNumber != null && p.CitationNumber.Contains(id)) ||
(p.PkCaseId.ToString() == id) ||
(p.CourtDatetime != null && EF.Functions.DateDiffDay(p.CourtDatetime, parsedDate) == 0) || // Compare CourtDatetime as DateTime
(p.ViolationDate != null && EF.Functions.DateDiffDay(p.ViolationDate, parsedDate) == 0)) // Compare ViolationDate as DateTime
.ToListAsync();

Console.WriteLine(_context.SearchScreens.Where(p =>
(p.LastName != null && p.LastName.Contains(id)) ||
(p.FirstName != null && p.FirstName.Contains(id)) ||
(p.CitationNumber != null && p.CitationNumber.Contains(id)) ||
(p.PkCaseId.ToString() == id) ||
(p.CourtDatetime != null && EF.Functions.DateDiffDay(p.CourtDatetime, parsedDate) == 0) || // Compare CourtDatetime as DateTime
(p.ViolationDate != null && EF.Functions.DateDiffDay(p.ViolationDate, parsedDate) == 0))
.GroupBy(p => p.PkCaseId)
.ToQueryString());

if (searchScreenViews == null || searchScreenViews.Count == 0)
{
return NotFound();
}

return searchScreenViews;
}
// GET: api/SearchScreenViews/5
[HttpGet("{id}")]
public async Task<ActionResult<IEnumerable<SearchScreenView>>> GetSearchScreenView(string id)
{
if (string.IsNullOrEmpty(id))
{
return NotFound();
}

DateTime.TryParse(id, out DateTime parsedDate); // Parse input string to DateTime

var searchScreenViews = await _context.SearchScreens
.Where(p =>
(p.LastName != null && p.LastName.Contains(id)) ||
(p.FirstName != null && p.FirstName.Contains(id)) ||
(p.CitationNumber != null && p.CitationNumber.Contains(id)) ||
(p.PkCaseId.ToString() == id) ||
(p.CourtDatetime != null && EF.Functions.DateDiffDay(p.CourtDatetime, parsedDate) == 0) || // Compare CourtDatetime as DateTime
(p.ViolationDate != null && EF.Functions.DateDiffDay(p.ViolationDate, parsedDate) == 0)) // Compare ViolationDate as DateTime
.ToListAsync();

Console.WriteLine(_context.SearchScreens.Where(p =>
(p.LastName != null && p.LastName.Contains(id)) ||
(p.FirstName != null && p.FirstName.Contains(id)) ||
(p.CitationNumber != null && p.CitationNumber.Contains(id)) ||
(p.PkCaseId.ToString() == id) ||
(p.CourtDatetime != null && EF.Functions.DateDiffDay(p.CourtDatetime, parsedDate) == 0) || // Compare CourtDatetime as DateTime
(p.ViolationDate != null && EF.Functions.DateDiffDay(p.ViolationDate, parsedDate) == 0))
.GroupBy(p => p.PkCaseId)
.ToQueryString());

if (searchScreenViews == null || searchScreenViews.Count == 0)
{
return NotFound();
}

return searchScreenViews;
}
3 Replies
JakenVeina
JakenVeina2y ago
what is a "case"?
crackTheCliff
crackTheCliffOP2y ago
So basically I created a view in the SQL DB. And I am searching for a name or case or citation number. And if I get matched results it will return that view. @JakenVeina So for instance let's say I search Jones and there are 13 people with the last name Jones, it will return 13 views but all 13 of them are the first one that was returned.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server