using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Abp.Domain.Entities;
using Abp.Domain.Repositories;
using Microsoft.EntityFrameworkCore;

namespace YGNT.Infrastructure.Extension
{
    public static class AbpRepositoryExtension
    {
        public static bool Any<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository,
            Expression<Func<TEntity, bool>> predicate) where TEntity : class, IEntity<TPrimaryKey>
        {
            return repository.GetAll().Any(predicate);
        }

        public static Task<bool> AnyAsync<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository,
            Expression<Func<TEntity, bool>> predicate) where TEntity : class, IEntity<TPrimaryKey>
        {
            return repository.GetAll().AnyAsync(predicate);
        }
    }
}