예제 #1
0
        public static async Task HardDeleteAsync <TEntity>(
            this IBasicRepository <TEntity> repository,
            TEntity entity,
            bool autoSave = false,
            CancellationToken cancellationToken = default
            )
            where TEntity : class, IEntity, ISoftDelete
        {
            if (!(ProxyHelper.UnProxy(repository) is IUnitOfWorkManagerAccessor unitOfWorkManagerAccessor))
            {
                throw new AbpException($"The given repository (of type {repository.GetType().AssemblyQualifiedName}) should implement the {typeof(IUnitOfWorkManagerAccessor).AssemblyQualifiedName} interface in order to invoke the {nameof(HardDeleteAsync)} method!");
            }

            var uowManager = unitOfWorkManagerAccessor.UnitOfWorkManager;

            if (uowManager == null)
            {
                throw new AbpException($"{nameof(unitOfWorkManagerAccessor.UnitOfWorkManager)} property of the given {nameof(repository)} object is null!");
            }

            if (uowManager.Current == null)
            {
                using (var uow = uowManager.Begin())
                {
                    await HardDeleteWithUnitOfWorkAsync(repository, entity, autoSave, cancellationToken, uowManager.Current);

                    await uow.CompleteAsync(cancellationToken);
                }
            }
            else
            {
                await HardDeleteWithUnitOfWorkAsync(repository, entity, autoSave, cancellationToken, uowManager.Current);
            }
        }
예제 #2
0
    private static IUnitOfWorkManager GetUnitOfWorkManager<TEntity>(
        this IBasicRepository<TEntity> repository,
        [CallerMemberName] string callingMethodName = nameof(GetUnitOfWorkManager)
    )
        where TEntity : class, IEntity
    {
        if (ProxyHelper.UnProxy(repository) is not IUnitOfWorkManagerAccessor unitOfWorkManagerAccessor)
        {
            throw new AbpException($"The given repository (of type {repository.GetType().AssemblyQualifiedName}) should implement the " +
                $"{typeof(IUnitOfWorkManagerAccessor).AssemblyQualifiedName} interface in order to invoke the {callingMethodName} method!");
        }

        if (unitOfWorkManagerAccessor.UnitOfWorkManager == null)
        {
            throw new AbpException($"{nameof(unitOfWorkManagerAccessor.UnitOfWorkManager)} property of the given {nameof(repository)} object is null!");
        }

        return unitOfWorkManagerAccessor.UnitOfWorkManager;
    }