Darstellung der Prospects fragmentiert
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using FoodsharingSiegen.Contracts;
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Contracts.Model;
|
||||
using FoodsharingSiegen.Server.Auth;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -103,12 +104,18 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
/// Gets the users (a. beging, 01.04.2022)
|
||||
/// </summary>
|
||||
/// <returns>A task containing an operation result of list prospect</returns>
|
||||
public async Task<OperationResult<List<Prospect>>> GetProspectsAsync(InteractionType? filterType = null)
|
||||
public async Task<OperationResult<List<Prospect>>> GetProspectsAsync(GetProspectsParameter parameter)
|
||||
{
|
||||
try
|
||||
{
|
||||
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));
|
||||
|
||||
if(parameter.MustHaveInteractions != null && parameter.MustHaveInteractions.Any())
|
||||
prospectsQuery = prospectsQuery.Where(x => x.Interactions.Any(i => parameter.MustHaveInteractions.Contains(i.Type)));
|
||||
|
||||
if(parameter.CannotHaveInteractions != null && parameter.CannotHaveInteractions.Any())
|
||||
prospectsQuery = prospectsQuery.Where(x => x.Interactions.All(i => !parameter.CannotHaveInteractions.Contains(i.Type)));
|
||||
|
||||
var prospects = await prospectsQuery.ToListAsync();
|
||||
|
||||
return new OperationResult<List<Prospect>>(prospects);
|
||||
|
||||
Reference in New Issue
Block a user