public static IQueryable <Registration> AddFilter(
            this IQueryable <Registration> query,
            RegistrationFilter filter)
        {
            if (filter == null)
            {
                return(query);
            }

            if (filter.VerifiedOnly)
            {
                query = query.Where(r => r.Verified);
            }

            if (filter.ActiveUsersOnly)
            {
                query = query.Where(r => !r.User.Archived);
            }

            if (filter.HavingEmailConfirmedOnly)
            {
                query = query.Where(r => r.User.EmailConfirmed);
            }

            if (filter.EventInfoId.HasValue)
            {
                query = query.Where(r => r.EventInfoId == filter.EventInfoId);
            }

            if (!string.IsNullOrEmpty(filter.UserId))
            {
                query = query.Where(r => r.UserId == filter.UserId);
            }

            if (filter.HavingStatuses?.Any() == true)
            {
                query = query.Where(r => filter.HavingStatuses.Contains(r.Status));
            }

            if (filter.HavingTypes?.Any() == true)
            {
                query = query.Where(r => filter.HavingTypes.Contains(r.Type));
            }

            return(query);
        }
        public async Task <Registration> FindRegistrationAsync(
            RegistrationFilter filter,
            RegistrationRetrievalOptions options,
            CancellationToken cancellationToken)
        {
            options ??= RegistrationRetrievalOptions.Default;

            var query = _context.Registrations
                        .WithOptions(options)
                        .AddFilter(filter);

            if (filter.AccessibleOnly)
            {
                query = await _registrationAccessControlService
                        .AddAccessFilterAsync(query, cancellationToken);
            }

            return(await query.FirstOrDefaultAsync(cancellationToken));
        }