dotnet-cqrs/Demo/DynamicQueries/SearchContactParamsService.cs

17 lines
643 B
C#

using PoweredSoft.CQRS.DynamicQuery.Abstractions;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Demo.DynamicQueries
{
public class SearchContactParamsService : IAlterQueryableService<Contact, Contact, SearchContactParams>
{
public Task<IQueryable<Contact>> AlterQueryableAsync(IQueryable<Contact> query, IDynamicQueryParams<SearchContactParams> dynamicQuery, CancellationToken cancellationToken = default)
{
var safe = dynamicQuery.GetParams()?.SearchDisplayName;
return Task.FromResult(query.Where(t => t.DisplayName.Contains(safe)));
}
}
}