Filtern der Prospects ermöglichen

This commit is contained in:
Andre Beging
2023-02-07 22:19:41 +01:00
parent 3bded89061
commit de7605578a

View File

@@ -103,11 +103,14 @@ namespace FoodsharingSiegen.Server.Data.Service
/// Gets the users (a. beging, 01.04.2022) /// Gets the users (a. beging, 01.04.2022)
/// </summary> /// </summary>
/// <returns>A task containing an operation result of list prospect</returns> /// <returns>A task containing an operation result of list prospect</returns>
public async Task<OperationResult<List<Prospect>>> GetProspectsAsync() public async Task<OperationResult<List<Prospect>>> GetProspectsAsync(InteractionType? filterType = null)
{ {
try try
{ {
var prospects = await Context.Prospects!.AsNoTracking().Include(x => x.Interactions.OrderBy(i => i.Date)).ThenInclude(x => x.User).OrderBy(x => x.Name).ToListAsync(); var prospectsQuery = Context.Prospects!.AsNoTracking().Include(x => x.Interactions.OrderBy(i => i.Date)).ThenInclude(x => x.User).OrderBy(x => x.Name).AsQueryable();
if(filterType != null) prospectsQuery = prospectsQuery.Where(x => x.Interactions.Any(i => i.Type == filterType));
var prospects = await prospectsQuery.ToListAsync();
return new OperationResult<List<Prospect>>(prospects); return new OperationResult<List<Prospect>>(prospects);
} }
catch (Exception e) catch (Exception e)