mirror of https://github.com/abpframework/abp.git
committed by
GitHub
3 changed files with 51 additions and 92 deletions
@ -1,20 +0,0 @@ |
|||||
using MongoDB.Driver; |
|
||||
using System.Collections.Generic; |
|
||||
using Volo.Abp.Domain.Entities; |
|
||||
|
|
||||
namespace Volo.Abp.Domain.Repositories.MongoDB |
|
||||
{ |
|
||||
public interface IMongoDbRepositoryFilterer<TEntity> |
|
||||
where TEntity : class, IEntity |
|
||||
{ |
|
||||
void AddGlobalFilters(List<FilterDefinition<TEntity>> filters); |
|
||||
} |
|
||||
|
|
||||
public interface IMongoDbRepositoryFilterer<TEntity, TKey> : IMongoDbRepositoryFilterer<TEntity> |
|
||||
where TEntity : class, IEntity<TKey> |
|
||||
{ |
|
||||
FilterDefinition<TEntity> CreateEntityFilter(TKey id, bool applyFilters = false); |
|
||||
|
|
||||
FilterDefinition<TEntity> CreateEntityFilter(TEntity entity, bool withConcurrencyStamp = false, string concurrencyStamp = null); |
|
||||
} |
|
||||
} |
|
||||
@ -1,68 +0,0 @@ |
|||||
using MongoDB.Driver; |
|
||||
using System.Collections.Generic; |
|
||||
using Volo.Abp.Data; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
using Volo.Abp.Domain.Entities; |
|
||||
using Volo.Abp.MultiTenancy; |
|
||||
|
|
||||
namespace Volo.Abp.Domain.Repositories.MongoDB |
|
||||
{ |
|
||||
public class MongoDbRepositoryFilterer<TEntity> : IMongoDbRepositoryFilterer<TEntity>, ITransientDependency |
|
||||
where TEntity : class, IEntity |
|
||||
{ |
|
||||
public IDataFilter DataFilter { get; set; } |
|
||||
|
|
||||
public ICurrentTenant CurrentTenant { get; set; } |
|
||||
|
|
||||
public void AddGlobalFilters(List<FilterDefinition<TEntity>> filters) |
|
||||
{ |
|
||||
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && DataFilter.IsEnabled<ISoftDelete>()) |
|
||||
{ |
|
||||
filters.Add(Builders<TEntity>.Filter.Eq(e => ((ISoftDelete)e).IsDeleted, false)); |
|
||||
} |
|
||||
|
|
||||
if (typeof(IMultiTenant).IsAssignableFrom(typeof(TEntity))) |
|
||||
{ |
|
||||
var tenantId = CurrentTenant.Id; |
|
||||
filters.Add(Builders<TEntity>.Filter.Eq(e => ((IMultiTenant)e).TenantId, tenantId)); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public class MongoDbRepositoryFilterer<TEntity, TKey> : MongoDbRepositoryFilterer<TEntity>, IMongoDbRepositoryFilterer<TEntity, TKey>, ITransientDependency |
|
||||
where TEntity : class, IEntity<TKey> |
|
||||
{ |
|
||||
public FilterDefinition<TEntity> CreateEntityFilter(TKey id, bool applyFilters = false) |
|
||||
{ |
|
||||
var filters = new List<FilterDefinition<TEntity>> |
|
||||
{ |
|
||||
Builders<TEntity>.Filter.Eq(e => e.Id, id) |
|
||||
}; |
|
||||
|
|
||||
if (applyFilters) |
|
||||
{ |
|
||||
AddGlobalFilters(filters); |
|
||||
} |
|
||||
|
|
||||
return Builders<TEntity>.Filter.And(filters); |
|
||||
} |
|
||||
|
|
||||
public FilterDefinition<TEntity> CreateEntityFilter(TEntity entity, bool withConcurrencyStamp = false, string concurrencyStamp = null) |
|
||||
{ |
|
||||
if (!withConcurrencyStamp || !(entity is IHasConcurrencyStamp entityWithConcurrencyStamp)) |
|
||||
{ |
|
||||
return Builders<TEntity>.Filter.Eq(e => e.Id, entity.Id); |
|
||||
} |
|
||||
|
|
||||
if (concurrencyStamp == null) |
|
||||
{ |
|
||||
concurrencyStamp = entityWithConcurrencyStamp.ConcurrencyStamp; |
|
||||
} |
|
||||
|
|
||||
return Builders<TEntity>.Filter.And( |
|
||||
Builders<TEntity>.Filter.Eq(e => e.Id, entity.Id), |
|
||||
Builders<TEntity>.Filter.Eq(e => ((IHasConcurrencyStamp)e).ConcurrencyStamp, concurrencyStamp) |
|
||||
); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue