- Convert Tenant to anemia model with long Id (no strong-typed ID) - Add ApplicationUser, ApplicationRole to Platform.Domain (inherit Identity) - Add TenantInfo value object for user-tenant redundancy - Implement TenantManager/TenantStore in Platform.Infrastructure - Update PlatformDbContext to inherit IdentityDbContext - Migrate AuthService and Console to use Platform entities - Remove old TenantRepository (replaced by TenantManager) - Update AGENTS.md documentation
82 lines
3.7 KiB
C#
82 lines
3.7 KiB
C#
namespace Fengling.Platform.Infrastructure;
|
|
|
|
using Fengling.Platform.Domain.AggregatesModel.TenantAggregate;
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
public interface ITenantManager
|
|
{
|
|
Task<Tenant?> FindByIdAsync(long tenantId, CancellationToken cancellationToken = default);
|
|
Task<Tenant?> FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default);
|
|
Task<IList<Tenant>> GetAllAsync(CancellationToken cancellationToken = default);
|
|
Task<IList<Tenant>> GetPagedAsync(int page, int pageSize, string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default);
|
|
Task<int> GetCountAsync(string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default);
|
|
Task<IdentityResult> CreateAsync(Tenant tenant, CancellationToken cancellationToken = default);
|
|
Task<IdentityResult> UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default);
|
|
Task<IdentityResult> DeleteAsync(Tenant tenant, CancellationToken cancellationToken = default);
|
|
Task<int> GetUserCountAsync(long tenantId, CancellationToken cancellationToken = default);
|
|
Task<IdentityResult> SetTenantCodeAsync(Tenant tenant, string code, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
public class TenantManager : ITenantManager
|
|
{
|
|
private readonly ITenantStore _store;
|
|
|
|
public TenantManager(ITenantStore store)
|
|
{
|
|
_store = store;
|
|
}
|
|
|
|
public virtual async Task<Tenant?> FindByIdAsync(long tenantId, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _store.FindByIdAsync(tenantId, cancellationToken);
|
|
}
|
|
|
|
public virtual async Task<Tenant?> FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _store.FindByTenantCodeAsync(tenantCode, cancellationToken);
|
|
}
|
|
|
|
public virtual async Task<IList<Tenant>> GetAllAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
return await _store.GetAllAsync(cancellationToken);
|
|
}
|
|
|
|
public virtual async Task<IList<Tenant>> GetPagedAsync(int page, int pageSize, string? name = null,
|
|
string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _store.GetPagedAsync(page, pageSize, name, tenantCode, status, cancellationToken);
|
|
}
|
|
|
|
public virtual async Task<int> GetCountAsync(string? name = null, string? tenantCode = null,
|
|
TenantStatus? status = null, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _store.GetCountAsync(name, tenantCode, status, cancellationToken);
|
|
}
|
|
|
|
public virtual async Task<IdentityResult> CreateAsync(Tenant tenant, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _store.CreateAsync(tenant, cancellationToken);
|
|
}
|
|
|
|
public virtual async Task<IdentityResult> UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _store.UpdateAsync(tenant, cancellationToken);
|
|
}
|
|
|
|
public virtual async Task<IdentityResult> DeleteAsync(Tenant tenant, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _store.DeleteAsync(tenant, cancellationToken);
|
|
}
|
|
|
|
public virtual async Task<int> GetUserCountAsync(long tenantId, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _store.GetUserCountAsync(tenantId, cancellationToken);
|
|
}
|
|
|
|
public virtual async Task<IdentityResult> SetTenantCodeAsync(Tenant tenant, string code, CancellationToken cancellationToken = default)
|
|
{
|
|
await _store.SetTenantCodeAsync(tenant, code, cancellationToken);
|
|
return IdentityResult.Success;
|
|
}
|
|
}
|