diff --git a/src/ReC.Application/Results/Queries/AnyResultViewQuery.cs b/src/ReC.Application/Results/Queries/AnyResultViewQuery.cs new file mode 100644 index 0000000..567cd4e --- /dev/null +++ b/src/ReC.Application/Results/Queries/AnyResultViewQuery.cs @@ -0,0 +1,35 @@ +using DigitalData.Core.Abstraction.Application.Repository; +using MediatR; +using Microsoft.EntityFrameworkCore; +using ReC.Domain.Views; + +namespace ReC.Application.Results.Queries; + +public record AnyResultViewQuery( + long? Id = null, + long? ActionId = null, + long? ProfileId = null, + string? BatchId = null +) : IRequest; + +public class AnyResultViewQueryHandler(IRepository repo) : IRequestHandler +{ + public Task Handle(AnyResultViewQuery request, CancellationToken cancel) + { + var q = repo.Query; + + if(request.Id is long id) + q = q.Where(rv => rv.Id == id); + + if(request.ActionId is long actionId) + q = q.Where(rv => rv.ActionId == actionId); + + if(request.ProfileId is long profileId) + q = q.Where(rv => rv.ProfileId == profileId); + + if(request.BatchId is string batchId) + q = q.Where(rv => rv.BatchId == batchId); + + return q.AnyAsync(cancel); + } +} \ No newline at end of file