crackTheCliff
crackTheCliff
CC#
Created by crackTheCliff on 5/2/2023 in #help
❔ 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;
}
5 replies