| | | 1 | | using Elsa.Common.Multitenancy; |
| | | 2 | | using Elsa.Tenants; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Persistence.EFCore.Modules.Tenants; |
| | | 6 | | |
| | | 7 | | [UsedImplicitly] |
| | 0 | 8 | | public class EFCoreTenantStore(EntityStore<TenantsElsaDbContext, Tenant> store) : ITenantStore |
| | | 9 | | { |
| | | 10 | | public async Task<Tenant?> FindAsync(TenantFilter filter, CancellationToken cancellationToken = default) |
| | | 11 | | { |
| | 0 | 12 | | return await store.FindAsync(query => Filter(query, filter), cancellationToken); |
| | 0 | 13 | | } |
| | | 14 | | |
| | | 15 | | public async Task<Tenant?> FindAsync(string id, CancellationToken cancellationToken = default) |
| | | 16 | | { |
| | 0 | 17 | | var filter = TenantFilter.ById(id); |
| | 0 | 18 | | return await FindAsync(filter, cancellationToken); |
| | 0 | 19 | | } |
| | | 20 | | |
| | | 21 | | public async Task<IEnumerable<Tenant>> FindManyAsync(TenantFilter filter, CancellationToken cancellationToken = defa |
| | | 22 | | { |
| | 0 | 23 | | return await store.QueryAsync(queryable => Filter(queryable, filter), cancellationToken); |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | public async Task<IEnumerable<Tenant>> ListAsync(CancellationToken cancellationToken = default) |
| | | 27 | | { |
| | 0 | 28 | | return await store.ListAsync(cancellationToken); |
| | 0 | 29 | | } |
| | | 30 | | |
| | | 31 | | public async Task AddAsync(Tenant tenant, CancellationToken cancellationToken = default) |
| | | 32 | | { |
| | 0 | 33 | | await store.AddAsync(tenant, cancellationToken); |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | public async Task UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default) |
| | | 37 | | { |
| | 0 | 38 | | await store.UpdateAsync(tenant, cancellationToken); |
| | 0 | 39 | | } |
| | | 40 | | |
| | | 41 | | public async Task<bool> DeleteAsync(string id, CancellationToken cancellationToken = default) |
| | | 42 | | { |
| | 0 | 43 | | var filter = TenantFilter.ById(id); |
| | 0 | 44 | | var count = await DeleteAsync(filter, cancellationToken); |
| | 0 | 45 | | return count > 0; |
| | 0 | 46 | | } |
| | | 47 | | |
| | | 48 | | public async Task<long> DeleteAsync(TenantFilter filter, CancellationToken cancellationToken = default) |
| | | 49 | | { |
| | 0 | 50 | | return await store.DeleteWhereAsync(query => Filter(query, filter), cancellationToken); |
| | 0 | 51 | | } |
| | | 52 | | |
| | 0 | 53 | | private static IQueryable<Tenant> Filter(IQueryable<Tenant> query, TenantFilter filter) => filter.Apply(query); |
| | | 54 | | } |