diff --git a/Datas/ApplicationDbContext.cs b/Datas/ApplicationDbContext.cs deleted file mode 100644 index 5097451..0000000 --- a/Datas/ApplicationDbContext.cs +++ /dev/null @@ -1,69 +0,0 @@ -using Fengling.Console.Models.Entities; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore; -using System.Reflection; - -namespace Fengling.Console.Datas; - -public class ApplicationDbContext(DbContextOptions options) - : IdentityDbContext(options) -{ - public DbSet Tenants { get; set; } - public DbSet AccessLogs { get; set; } - public DbSet AuditLogs { get; set; } - - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); - - builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); - - builder.Entity(entity => - { - entity.Property(e => e.RealName).HasMaxLength(100); - entity.Property(e => e.Phone).HasMaxLength(20); - entity.HasIndex(e => e.Phone).IsUnique(); - }); - - builder.Entity(entity => { entity.Property(e => e.Description).HasMaxLength(200); }); - - - - builder.Entity(entity => - { - entity.HasKey(e => e.Id); - entity.HasIndex(e => e.CreatedAt); - entity.HasIndex(e => e.UserName); - entity.HasIndex(e => e.TenantId); - entity.HasIndex(e => e.Action); - entity.HasIndex(e => e.Status); - entity.Property(e => e.UserName).HasMaxLength(50); - entity.Property(e => e.TenantId).HasMaxLength(50); - entity.Property(e => e.Action).HasMaxLength(20); - entity.Property(e => e.Resource).HasMaxLength(200); - entity.Property(e => e.Method).HasMaxLength(10); - entity.Property(e => e.IpAddress).HasMaxLength(50); - entity.Property(e => e.UserAgent).HasMaxLength(500); - entity.Property(e => e.Status).HasMaxLength(20); - }); - - builder.Entity(entity => - { - entity.HasKey(e => e.Id); - entity.HasIndex(e => e.CreatedAt); - entity.HasIndex(e => e.Operator); - entity.HasIndex(e => e.TenantId); - entity.HasIndex(e => e.Operation); - entity.HasIndex(e => e.Action); - entity.Property(e => e.Operator).HasMaxLength(50); - entity.Property(e => e.TenantId).HasMaxLength(50); - entity.Property(e => e.Operation).HasMaxLength(20); - entity.Property(e => e.Action).HasMaxLength(20); - entity.Property(e => e.TargetType).HasMaxLength(50); - entity.Property(e => e.TargetName).HasMaxLength(100); - entity.Property(e => e.IpAddress).HasMaxLength(50); - entity.Property(e => e.Description).HasMaxLength(500); - entity.Property(e => e.Status).HasMaxLength(20); - }); - } -} \ No newline at end of file diff --git a/EntityConfigurations/TenantEntityTypeConfiguration.cs b/EntityConfigurations/TenantEntityTypeConfiguration.cs deleted file mode 100644 index 05f9d9c..0000000 --- a/EntityConfigurations/TenantEntityTypeConfiguration.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace Fengling.Console.EntityConfigurations; - -using Fengling.Console.Models.Entities; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -public class TenantEntityTypeConfiguration : IEntityTypeConfiguration -{ - public void Configure(EntityTypeBuilder builder) - { - builder.ToTable("Tenants"); - builder.HasKey(x => x.Id); - - builder.Property(x => x.Id) - .ValueGeneratedOnAdd(); - - builder.Property(x => x.TenantCode) - .IsRequired() - .HasMaxLength(50); - - builder.Property(x => x.Name) - .IsRequired() - .HasMaxLength(100); - - builder.Property(x => x.ContactName) - .IsRequired() - .HasMaxLength(50); - - builder.Property(x => x.ContactEmail) - .IsRequired() - .HasMaxLength(100); - - builder.HasIndex(x => x.TenantCode).IsUnique(); - builder.HasIndex(x => x.Name); - } -} diff --git a/Managers/TenantManager.cs b/Managers/TenantManager.cs deleted file mode 100644 index 6b5e8be..0000000 --- a/Managers/TenantManager.cs +++ /dev/null @@ -1,88 +0,0 @@ -using Fengling.Console.Models.Entities; -using Fengling.Console.Stores; -using Microsoft.AspNetCore.Identity; - -namespace Fengling.Console.Managers; - -public interface ITenantManager -{ - Task FindByIdAsync(int tenantId, CancellationToken cancellationToken = default); - Task FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default); - Task> GetAllAsync(CancellationToken cancellationToken = default); - Task> GetPagedAsync(int page, int pageSize, string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default); - Task GetCountAsync(string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default); - Task CreateAsync(Tenant tenant, CancellationToken cancellationToken = default); - Task UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default); - Task DeleteAsync(Tenant tenant, CancellationToken cancellationToken = default); - Task GetUserCountAsync(int tenantId, CancellationToken cancellationToken = default); - Task 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 FindByIdAsync(int tenantId, CancellationToken cancellationToken = default) - { - return await _store.FindByIdAsync(tenantId, cancellationToken); - } - - public virtual async Task FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default) - { - return await _store.FindByTenantCodeAsync(tenantCode, cancellationToken); - } - - public virtual async Task> GetAllAsync(CancellationToken cancellationToken = default) - { - return await _store.GetAllAsync(cancellationToken); - } - - public virtual async Task> 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 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 CreateAsync(Tenant tenant, CancellationToken cancellationToken = default) - { - return await _store.CreateAsync(tenant, cancellationToken); - } - - public virtual async Task UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default) - { - return await _store.UpdateAsync(tenant, cancellationToken); - } - - public virtual async Task DeleteAsync(Tenant tenant, CancellationToken cancellationToken = default) - { - return await _store.DeleteAsync(tenant, cancellationToken); - } - - public virtual async Task GetUserCountAsync(int tenantId, CancellationToken cancellationToken = default) - { - return await _store.GetUserCountAsync(tenantId, cancellationToken); - } - - public virtual async Task SetTenantCodeAsync(Tenant tenant, string code, CancellationToken cancellationToken = default) - { - var existing = await _store.FindByTenantCodeAsync(code, cancellationToken); - if (existing != null && existing.Id != tenant.Id) - { - return IdentityResult.Failed(new IdentityError { Description = "租户编码已存在" }); - } - - await _store.SetTenantCodeAsync(tenant, code, cancellationToken); - return IdentityResult.Success; - } -} diff --git a/Models/Dtos/TenantDto.cs b/Models/Dtos/TenantDto.cs index bb10c1d..26ca98d 100644 --- a/Models/Dtos/TenantDto.cs +++ b/Models/Dtos/TenantDto.cs @@ -1,10 +1,10 @@ -using Fengling.Console.Models.Entities; +using Fengling.Platform.Domain.AggregatesModel.TenantAggregate; namespace Fengling.Console.Models.Dtos; public class TenantDto { - public int Id { get; set; } + public long Id { get; set; } public string TenantCode { get; set; } = ""; public string Name { get; set; } = ""; public string ContactName { get; set; } = ""; @@ -12,7 +12,7 @@ public class TenantDto public string? ContactPhone { get; set; } public int? MaxUsers { get; set; } public int UserCount { get; set; } - public TenantStatus Status { get; set; } = TenantStatus.Active; + public TenantStatus Status { get; set; } = TenantStatus.Active; public DateTime? ExpiresAt { get; set; } public string? Description { get; set; } public DateTime CreatedAt { get; set; } diff --git a/Models/Dtos/TenantQueryDto.cs b/Models/Dtos/TenantQueryDto.cs index c3148cd..deb694a 100644 --- a/Models/Dtos/TenantQueryDto.cs +++ b/Models/Dtos/TenantQueryDto.cs @@ -1,4 +1,4 @@ -using Fengling.Console.Models.Entities; +using Fengling.Platform.Domain.AggregatesModel.TenantAggregate; namespace Fengling.Console.Models.Dtos; diff --git a/Models/Entities/AccessLog.cs b/Models/Entities/AccessLog.cs deleted file mode 100644 index afd0a9b..0000000 --- a/Models/Entities/AccessLog.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Fengling.Console.Models.Entities; - -public class AccessLog -{ - [Key] - public long Id { get; set; } - - [MaxLength(50)] - public string? UserName { get; set; } - - [MaxLength(50)] - public string? TenantId { get; set; } - - [MaxLength(20)] - public string Action { get; set; } = string.Empty; - - [MaxLength(200)] - public string? Resource { get; set; } - - [MaxLength(10)] - public string? Method { get; set; } - - [MaxLength(50)] - public string? IpAddress { get; set; } - - [MaxLength(500)] - public string? UserAgent { get; set; } - - [MaxLength(20)] - public string Status { get; set; } = "success"; - - public int Duration { get; set; } - - public string? RequestData { get; set; } - - public string? ResponseData { get; set; } - - public string? ErrorMessage { get; set; } - - public DateTime CreatedAt { get; set; } = DateTime.UtcNow; -} diff --git a/Models/Entities/ApplicationRole.cs b/Models/Entities/ApplicationRole.cs deleted file mode 100644 index b5aa616..0000000 --- a/Models/Entities/ApplicationRole.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Microsoft.AspNetCore.Identity; - -namespace Fengling.Console.Models.Entities; - -public class ApplicationRole : IdentityRole -{ - public string? Description { get; set; } - public DateTime CreatedTime { get; set; } = DateTime.UtcNow; - public int? TenantId { get; set; } - public bool IsSystem { get; set; } - public string? DisplayName { get; set; } - public List? Permissions { get; set; } -} diff --git a/Models/Entities/ApplicationUser.cs b/Models/Entities/ApplicationUser.cs deleted file mode 100644 index 3478cf3..0000000 --- a/Models/Entities/ApplicationUser.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Microsoft.AspNetCore.Identity; - -namespace Fengling.Console.Models.Entities; - -public class ApplicationUser : IdentityUser -{ - public string? RealName { get; set; } - public string? Phone { get; set; } - public int TenantId { get; set; } - public DateTime CreatedTime { get; set; } = DateTime.UtcNow; - public DateTime? UpdatedTime { get; set; } - public bool IsDeleted { get; set; } -} diff --git a/Models/Entities/AuditLog.cs b/Models/Entities/AuditLog.cs deleted file mode 100644 index 4ea18df..0000000 --- a/Models/Entities/AuditLog.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Fengling.Console.Models.Entities; - -public class AuditLog -{ - [Key] - public long Id { get; set; } - - [MaxLength(50)] - [Required] - public string Operator { get; set; } = string.Empty; - - [MaxLength(50)] - public string? TenantId { get; set; } - - [MaxLength(20)] - public string Operation { get; set; } = string.Empty; - - [MaxLength(20)] - public string Action { get; set; } = string.Empty; - - [MaxLength(50)] - public string? TargetType { get; set; } - - public long? TargetId { get; set; } - - [MaxLength(100)] - public string? TargetName { get; set; } - - [MaxLength(50)] - public string IpAddress { get; set; } = string.Empty; - - [MaxLength(500)] - public string? Description { get; set; } - - public string? OldValue { get; set; } - - public string? NewValue { get; set; } - - public string? ErrorMessage { get; set; } - - [MaxLength(20)] - public string Status { get; set; } = "success"; - - public DateTime CreatedAt { get; set; } = DateTime.UtcNow; -} diff --git a/Models/Entities/Tenant.cs b/Models/Entities/Tenant.cs deleted file mode 100644 index 845a24a..0000000 --- a/Models/Entities/Tenant.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Fengling.Console.Models.Entities; - -public class Tenant -{ - public int Id { get; set; } - public string TenantCode { get; set; } = string.Empty; - public string Name { get; set; } = string.Empty; - public string ContactName { get; set; } = string.Empty; - public string ContactEmail { get; set; } = string.Empty; - public string? ContactPhone { get; set; } - public int? MaxUsers { get; set; } - public string? Description { get; set; } - public TenantStatus Status { get; set; } = TenantStatus.Active; - public DateTime? ExpiresAt { get; set; } - public DateTime CreatedAt { get; set; } = DateTime.UtcNow; - public DateTime? UpdatedAt { get; set; } - public bool IsDeleted { get; set; } -} - -public enum TenantStatus -{ - Active = 1, - Inactive = 2, - Frozen = 3 -} diff --git a/Program.cs b/Program.cs index 50be5c6..683708b 100644 --- a/Program.cs +++ b/Program.cs @@ -98,11 +98,6 @@ builder.Services.AddSwaggerGen(c => builder.Services.AddRepositories(typeof(PlatformDbContext).Assembly); -builder.Services.AddMediatR(cfg => - cfg.RegisterServicesFromAssemblies( - Assembly.GetExecutingAssembly(), - typeof(PlatformDbContext).Assembly - )); var app = builder.Build(); diff --git a/Repositories/IRoleRepository.cs b/Repositories/IRoleRepository.cs deleted file mode 100644 index 1f6ec45..0000000 --- a/Repositories/IRoleRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Fengling.Console.Models.Entities; - -namespace Fengling.Console.Repositories; - -public interface IRoleRepository -{ - Task GetByIdAsync(long id); - Task GetByNameAsync(string name); - Task> GetAllAsync(); - Task> GetPagedAsync(int page, int pageSize, string? name = null, string? tenantId = null); - Task CountAsync(string? name = null, string? tenantId = null); - Task AddAsync(ApplicationRole role); - Task UpdateAsync(ApplicationRole role); - Task DeleteAsync(ApplicationRole role); -} diff --git a/Repositories/IUserRepository.cs b/Repositories/IUserRepository.cs deleted file mode 100644 index 59fd279..0000000 --- a/Repositories/IUserRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Fengling.Console.Models.Entities; - -namespace Fengling.Console.Repositories; - -public interface IUserRepository -{ - Task GetByIdAsync(long id); - Task GetByUserNameAsync(string userName); - Task> GetAllAsync(); - Task> GetPagedAsync(int page, int pageSize, string? userName = null, string? email = null, string? tenantId = null); - Task CountAsync(string? userName = null, string? email = null, string? tenantId = null); - Task AddAsync(ApplicationUser user); - Task UpdateAsync(ApplicationUser user); - Task DeleteAsync(ApplicationUser user); -} diff --git a/Repositories/RoleRepository.cs b/Repositories/RoleRepository.cs deleted file mode 100644 index 8e09129..0000000 --- a/Repositories/RoleRepository.cs +++ /dev/null @@ -1,80 +0,0 @@ -using Fengling.Console.Datas; -using Fengling.Console.Models.Entities; -using Microsoft.EntityFrameworkCore; - -namespace Fengling.Console.Repositories; - -public class RoleRepository(ApplicationDbContext context) : IRoleRepository -{ - public async Task GetByIdAsync(long id) - { - return await context.Roles.FindAsync(id); - } - - public async Task GetByNameAsync(string name) - { - return await context.Roles.FirstOrDefaultAsync(r => r.Name == name); - } - - public async Task> GetAllAsync() - { - return await context.Roles.ToListAsync(); - } - - public async Task> GetPagedAsync(int page, int pageSize, string? name = null, - string? tenantId = null) - { - var query = context.Roles.AsQueryable(); - - if (!string.IsNullOrEmpty(name)) - { - query = query.Where(r => r.Name != null && r.Name.Contains(name)); - } - - if (!string.IsNullOrEmpty(tenantId)) - { - query = query.Where(r => r.TenantId.ToString() == tenantId); - } - - return await query - .OrderByDescending(r => r.CreatedTime) - .Skip((page - 1) * pageSize) - .Take(pageSize) - .ToListAsync(); - } - - public async Task CountAsync(string? name = null, string? tenantId = null) - { - var query = context.Roles.AsQueryable(); - - if (!string.IsNullOrEmpty(name)) - { - query = query.Where(r => r.Name != null && r.Name.Contains(name)); - } - - if (!string.IsNullOrEmpty(tenantId)) - { - query = query.Where(r => r.TenantId.ToString() == tenantId); - } - - return await query.CountAsync(); - } - - public async Task AddAsync(ApplicationRole role) - { - context.Roles.Add(role); - await context.SaveChangesAsync(); - } - - public async Task UpdateAsync(ApplicationRole role) - { - context.Roles.Update(role); - await context.SaveChangesAsync(); - } - - public async Task DeleteAsync(ApplicationRole role) - { - context.Roles.Remove(role); - await context.SaveChangesAsync(); - } -} \ No newline at end of file diff --git a/Repositories/UserRepository.cs b/Repositories/UserRepository.cs deleted file mode 100644 index 8b724bf..0000000 --- a/Repositories/UserRepository.cs +++ /dev/null @@ -1,97 +0,0 @@ -using Fengling.Console.Datas; -using Fengling.Console.Models.Entities; -using Microsoft.EntityFrameworkCore; - -namespace Fengling.Console.Repositories; - -public class UserRepository : IUserRepository -{ - private readonly ApplicationDbContext _context; - - public UserRepository(ApplicationDbContext context) - { - _context = context; - } - - public async Task GetByIdAsync(long id) - { - return await _context.Users.FindAsync(id); - } - - public async Task GetByUserNameAsync(string userName) - { - return await _context.Users.FirstOrDefaultAsync(u => u.UserName == userName); - } - - public async Task> GetAllAsync() - { - return await _context.Users.ToListAsync(); - } - - public async Task> GetPagedAsync(int page, int pageSize, string? userName = null, - string? email = null, string? tenantCode = null) - { - var query = _context.Users.AsQueryable(); - - if (!string.IsNullOrEmpty(userName)) - { - query = query.Where(u => u.UserName != null && u.UserName.Contains(userName)); - } - - if (!string.IsNullOrEmpty(email)) - { - query = query.Where(u => u.Email != null && u.Email.Contains(email)); - } - - if (!string.IsNullOrEmpty(tenantCode)) - { - query = query.Where(u => u.TenantId.ToString().Contains(tenantCode)); - } - - return await query - .OrderByDescending(u => u.CreatedTime) - .Skip((page - 1) * pageSize) - .Take(pageSize) - .ToListAsync(); - } - - public async Task CountAsync(string? userName = null, string? email = null, string? tenantCode = null) - { - var query = _context.Users.AsQueryable(); - - if (!string.IsNullOrEmpty(userName)) - { - query = query.Where(u => u.UserName != null && u.UserName.Contains(userName)); - } - - if (!string.IsNullOrEmpty(email)) - { - query = query.Where(u => u.Email != null && u.Email.Contains(email)); - } - - if (!string.IsNullOrEmpty(tenantCode)) - { - query = query.Where(u => u.TenantId.ToString().Contains(tenantCode)); - } - - return await query.CountAsync(); - } - - public async Task AddAsync(ApplicationUser user) - { - _context.Users.Add(user); - await _context.SaveChangesAsync(); - } - - public async Task UpdateAsync(ApplicationUser user) - { - _context.Users.Update(user); - await _context.SaveChangesAsync(); - } - - public async Task DeleteAsync(ApplicationUser user) - { - _context.Users.Remove(user); - await _context.SaveChangesAsync(); - } -} diff --git a/Services/H5LinkService.cs b/Services/H5LinkService.cs index 749f45c..02babcc 100644 --- a/Services/H5LinkService.cs +++ b/Services/H5LinkService.cs @@ -1,8 +1,6 @@ -using Fengling.Console.Models.Entities; -using Fengling.Console.Managers; +using Fengling.Platform.Infrastructure; using Microsoft.Extensions.Configuration; using QRCoder; -using Tenant = Fengling.Console.Models.Entities.Tenant; namespace Fengling.Console.Services; @@ -43,7 +41,7 @@ public class H5LinkService : IH5LinkService }; } - private string GenerateLink(Tenant tenant) + private string GenerateLink(Fengling.Platform.Domain.AggregatesModel.TenantAggregate.Tenant tenant) { var baseUrl = _configuration["AppSettings:DefaultH5BaseUrl"] ?? "https://h5.example.com"; return $"{baseUrl.TrimEnd('/')}/{tenant.TenantCode}"; diff --git a/Services/RoleService.cs b/Services/RoleService.cs index 676cbbd..6108519 100644 --- a/Services/RoleService.cs +++ b/Services/RoleService.cs @@ -1,10 +1,10 @@ using Fengling.Console.Models.Dtos; -using Fengling.Console.Repositories; -using Fengling.Console.Managers; +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using System.Security.Claims; -using Fengling.Console.Datas; -using Fengling.Console.Models.Entities; namespace Fengling.Console.Services; @@ -24,22 +24,19 @@ public interface IRoleService public class RoleService : IRoleService { - private readonly IRoleRepository _repository; private readonly ITenantManager _tenantManager; private readonly UserManager _userManager; private readonly RoleManager _roleManager; - private readonly ApplicationDbContext _context; + private readonly PlatformDbContext _context; private readonly IHttpContextAccessor _httpContextAccessor; public RoleService( - IRoleRepository repository, ITenantManager tenantManager, UserManager userManager, RoleManager roleManager, - ApplicationDbContext context, + PlatformDbContext context, IHttpContextAccessor httpContextAccessor) { - _repository = repository; _tenantManager = tenantManager; _userManager = userManager; _roleManager = roleManager; @@ -50,8 +47,24 @@ public class RoleService : IRoleService public async Task<(IEnumerable Items, int TotalCount)> GetRolesAsync(int page, int pageSize, string? name = null, string? tenantId = null) { - var roles = await _repository.GetPagedAsync(page, pageSize, name, tenantId); - var totalCount = await _repository.CountAsync(name, tenantId); + var query = _context.Roles.AsQueryable(); + + if (!string.IsNullOrEmpty(name)) + { + query = query.Where(r => r.Name != null && r.Name.Contains(name)); + } + + if (!string.IsNullOrEmpty(tenantId)) + { + query = query.Where(r => r.TenantId.HasValue && r.TenantId.Value.ToString().Contains(tenantId)); + } + + var totalCount = await query.CountAsync(); + var roles = await query + .OrderByDescending(r => r.CreatedTime) + .Skip((page - 1) * pageSize) + .Take(pageSize) + .ToListAsync(); var roleDtos = new List(); foreach (var role in roles) @@ -76,7 +89,7 @@ public class RoleService : IRoleService public async Task GetRoleAsync(long id) { - var role = await _repository.GetByIdAsync(id); + var role = await _context.Roles.FindAsync(id); if (role == null) return null; return new RoleDto @@ -95,7 +108,7 @@ public class RoleService : IRoleService public async Task> GetRoleUsersAsync(long id) { - var role = await _repository.GetByIdAsync(id); + var role = await _context.Roles.FindAsync(id); if (role == null) { throw new KeyNotFoundException($"Role with ID {id} not found"); @@ -107,14 +120,14 @@ public class RoleService : IRoleService foreach (var user in users) { var roles = await _userManager.GetRolesAsync(user); - var tenant = user.TenantId > 0 ? await _tenantManager.FindByIdAsync(user.TenantId) : null; + var tenant = user.TenantInfo.TenantId > 0 ? await _tenantManager.FindByIdAsync(user.TenantInfo.TenantId) : null; userDtos.Add(new UserDto { Id = user.Id, UserName = user.UserName, Email = user.Email, RealName = user.RealName, - TenantCode = user.TenantId.ToString(), + TenantCode = user.TenantInfo.TenantId.ToString(), TenantName = tenant?.Name ?? "", Roles = roles.ToList(), EmailConfirmed = user.EmailConfirmed, @@ -133,7 +146,7 @@ public class RoleService : IRoleService Name = dto.Name, DisplayName = dto.DisplayName, Description = dto.Description, - TenantId = dto.TenantId.HasValue ? (int?)dto.TenantId.Value : null, + TenantId = dto.TenantId.HasValue ? dto.TenantId.Value : null, Permissions = dto.Permissions, IsSystem = false, CreatedTime = DateTime.UtcNow @@ -164,7 +177,7 @@ public class RoleService : IRoleService public async Task UpdateRoleAsync(long id, UpdateRoleDto dto) { - var role = await _repository.GetByIdAsync(id); + var role = await _context.Roles.FindAsync(id); if (role == null) { throw new KeyNotFoundException($"Role with ID {id} not found"); @@ -181,7 +194,7 @@ public class RoleService : IRoleService role.Description = dto.Description; role.Permissions = dto.Permissions; - await _repository.UpdateAsync(role); + await _roleManager.UpdateAsync(role); await CreateAuditLog("role", "update", "Role", role.Id, role.DisplayName, oldValue, System.Text.Json.JsonSerializer.Serialize(role)); @@ -203,7 +216,7 @@ public class RoleService : IRoleService public async Task DeleteRoleAsync(long id) { - var role = await _repository.GetByIdAsync(id); + var role = await _context.Roles.FindAsync(id); if (role == null) { throw new KeyNotFoundException($"Role with ID {id} not found"); @@ -222,14 +235,14 @@ public class RoleService : IRoleService await _userManager.RemoveFromRoleAsync(user, role.Name!); } - await _repository.DeleteAsync(role); + await _roleManager.DeleteAsync(role); await CreateAuditLog("role", "delete", "Role", role.Id, role.DisplayName, oldValue); } public async Task AddUserToRoleAsync(long roleId, long userId) { - var role = await _repository.GetByIdAsync(roleId); + var role = await _context.Roles.FindAsync(roleId); if (role == null) { throw new KeyNotFoundException($"Role with ID {roleId} not found"); @@ -252,7 +265,7 @@ public class RoleService : IRoleService public async Task RemoveUserFromRoleAsync(long roleId, long userId) { - var role = await _repository.GetByIdAsync(roleId); + var role = await _context.Roles.FindAsync(roleId); if (role == null) { throw new KeyNotFoundException($"Role with ID {roleId} not found"); @@ -300,4 +313,4 @@ public class RoleService : IRoleService _context.AuditLogs.Add(log); await _context.SaveChangesAsync(); } -} \ No newline at end of file +} diff --git a/Services/TenantService.cs b/Services/TenantService.cs index 5bb39d5..9dfe176 100644 --- a/Services/TenantService.cs +++ b/Services/TenantService.cs @@ -1,11 +1,12 @@ -using Fengling.Console.Managers; using Fengling.Console.Models.Dtos; -using Fengling.Console.Repositories; +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Domain.AggregatesModel.TenantAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using System.Security.Claims; -using Fengling.Console.Datas; -using Fengling.Console.Models.Entities; -using TenantStatus = Fengling.Console.Models.Entities.TenantStatus; +using TenantStatus = Fengling.Platform.Domain.AggregatesModel.TenantAggregate.TenantStatus; namespace Fengling.Console.Services; @@ -13,22 +14,21 @@ public interface ITenantService { Task<(IEnumerable Items, int TotalCount)> GetTenantsAsync(int page, int pageSize, string? name = null, string? tenantCode = null, TenantStatus? status = null); - Task GetTenantAsync(int id); - Task> GetTenantUsersAsync(int tenantId); - Task> GetTenantRolesAsync(int tenantId); - Task GetTenantSettingsAsync(int id); - Task UpdateTenantSettingsAsync(int id, TenantSettingsDto settings); + Task GetTenantAsync(long id); + Task> GetTenantUsersAsync(long tenantId); + Task> GetTenantRolesAsync(long tenantId); + Task GetTenantSettingsAsync(long id); + Task UpdateTenantSettingsAsync(long id, TenantSettingsDto settings); Task CreateTenantAsync(CreateTenantDto dto); - Task UpdateTenantAsync(int id, UpdateTenantDto dto); - Task DeleteTenantAsync(int id); + Task UpdateTenantAsync(long id, UpdateTenantDto dto); + Task DeleteTenantAsync(long id); } public class TenantService( ITenantManager tenantManager, - IUserRepository userRepository, - IRoleRepository roleRepository, UserManager userManager, - ApplicationDbContext context, + RoleManager roleManager, + PlatformDbContext context, IHttpContextAccessor httpContextAccessor) : ITenantService { @@ -62,7 +62,7 @@ public class TenantService( return (tenantDtos, totalCount); } - public async Task GetTenantAsync(int id) + public async Task GetTenantAsync(long id) { var tenant = await tenantManager.FindByIdAsync(id); if (tenant == null) return null; @@ -84,7 +84,7 @@ public class TenantService( }; } - public async Task> GetTenantUsersAsync(int tenantId) + public async Task> GetTenantUsersAsync(long tenantId) { var tenant = await tenantManager.FindByIdAsync(tenantId); if (tenant == null) @@ -92,7 +92,10 @@ public class TenantService( throw new KeyNotFoundException($"Tenant with ID {tenantId} not found"); } - var users = await userRepository.GetPagedAsync(1, int.MaxValue, null, null, tenantId.ToString()); + var users = await context.Users + .Where(u => u.TenantInfo.TenantId == tenantId) + .ToListAsync(); + var userDtos = new List(); foreach (var user in users) @@ -104,7 +107,7 @@ public class TenantService( UserName = user.UserName, Email = user.Email, RealName = user.RealName, - TenantCode = user.TenantId.ToString(), + TenantCode = user.TenantInfo.TenantId.ToString(), TenantName = tenant?.Name ?? "", Roles = roles.ToList(), EmailConfirmed = user.EmailConfirmed, @@ -116,7 +119,7 @@ public class TenantService( return userDtos; } - public async Task> GetTenantRolesAsync(int tenantId) + public async Task> GetTenantRolesAsync(long tenantId) { var tenant = await tenantManager.FindByIdAsync(tenantId); if (tenant == null) @@ -124,7 +127,10 @@ public class TenantService( throw new KeyNotFoundException($"Tenant with ID {tenantId} not found"); } - var roles = await roleRepository.GetPagedAsync(1, int.MaxValue, null, tenantId.ToString()); + var roles = await context.Roles + .Where(r => r.TenantId == tenantId) + .ToListAsync(); + return roles.Select(r => new { id = r.Id, @@ -133,7 +139,7 @@ public class TenantService( }); } - public async Task GetTenantSettingsAsync(int id) + public async Task GetTenantSettingsAsync(long id) { var tenant = await tenantManager.FindByIdAsync(id); if (tenant == null) @@ -152,7 +158,7 @@ public class TenantService( }; } - public async Task UpdateTenantSettingsAsync(int id, TenantSettingsDto settings) + public async Task UpdateTenantSettingsAsync(long id, TenantSettingsDto settings) { var tenant = await tenantManager.FindByIdAsync(id); if (tenant == null) @@ -207,7 +213,7 @@ public class TenantService( }; } - public async Task UpdateTenantAsync(int id, UpdateTenantDto dto) + public async Task UpdateTenantAsync(long id, UpdateTenantDto dto) { var tenant = await tenantManager.FindByIdAsync(id); if (tenant == null) @@ -251,7 +257,7 @@ public class TenantService( }; } - public async Task DeleteTenantAsync(int id) + public async Task DeleteTenantAsync(long id) { var tenant = await tenantManager.FindByIdAsync(id); if (tenant == null) @@ -261,13 +267,16 @@ public class TenantService( var oldValue = System.Text.Json.JsonSerializer.Serialize(tenant); - var users = await userRepository.GetPagedAsync(1, int.MaxValue, null, null, id.ToString()); + var users = await context.Users + .Where(u => u.TenantInfo.TenantId == id) + .ToListAsync(); + foreach (var user in users) { user.IsDeleted = true; user.UpdatedTime = DateTime.UtcNow; - await context.SaveChangesAsync(); } + await context.SaveChangesAsync(); tenant.IsDeleted = true; var result = await tenantManager.UpdateAsync(tenant); @@ -281,7 +290,7 @@ public class TenantService( await CreateAuditLog("tenant", "delete", "Tenant", tenant.Id, tenant.Name, oldValue); } - private async Task CreateAuditLog(string operation, string action, string targetType, int? targetId, string? targetName, string? oldValue = null, string? newValue = null) + private async Task CreateAuditLog(string operation, string action, string targetType, long? targetId, string? targetName, string? oldValue = null, string? newValue = null) { var httpContext = httpContextAccessor.HttpContext; var userName = httpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier) ?? httpContext?.User?.Identity?.Name ?? "system"; @@ -294,7 +303,7 @@ public class TenantService( Operation = operation, Action = action, TargetType = targetType, - TargetId = targetId.HasValue ? (long)targetId.Value : null, + TargetId = targetId, TargetName = targetName, IpAddress = httpContext?.Connection?.RemoteIpAddress?.ToString() ?? "unknown", Status = "success", diff --git a/Services/UserService.cs b/Services/UserService.cs index 8a94dc3..e6bb793 100644 --- a/Services/UserService.cs +++ b/Services/UserService.cs @@ -1,11 +1,11 @@ using Fengling.Console.Models.Dtos; -using Fengling.Console.Repositories; -using Fengling.Console.Managers; +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Domain.AggregatesModel.TenantAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using System.Security.Claims; -using Fengling.Console.Datas; -using Fengling.Console.Models.Entities; -using Tenant = Fengling.Console.Models.Entities.Tenant; namespace Fengling.Console.Services; @@ -20,24 +20,44 @@ public interface IUserService } public class UserService( - IUserRepository repository, ITenantManager tenantManager, UserManager userManager, RoleManager roleManager, - ApplicationDbContext context, + PlatformDbContext context, IHttpContextAccessor httpContextAccessor) : IUserService { public async Task<(IEnumerable Items, int TotalCount)> GetUsersAsync(int page, int pageSize, string? userName = null, string? email = null, string? tenantId = null) { - var users = await repository.GetPagedAsync(page, pageSize, userName, email, tenantId); - var totalCount = await repository.CountAsync(userName, email, tenantId); + var query = context.Users.AsQueryable(); + + if (!string.IsNullOrEmpty(userName)) + { + query = query.Where(u => u.UserName != null && u.UserName.Contains(userName)); + } + + if (!string.IsNullOrEmpty(email)) + { + query = query.Where(u => u.Email != null && u.Email.Contains(email)); + } + + if (!string.IsNullOrEmpty(tenantId)) + { + query = query.Where(u => u.TenantInfo.TenantId.ToString().Contains(tenantId)); + } + + var totalCount = await query.CountAsync(); + var users = await query + .OrderByDescending(u => u.CreatedTime) + .Skip((page - 1) * pageSize) + .Take(pageSize) + .ToListAsync(); var userDtos = new List(); foreach (var user in users) { var roles = await userManager.GetRolesAsync(user); - var tenant = user.TenantId > 0 ? await tenantManager.FindByIdAsync(user.TenantId) : null; + var tenant = user.TenantInfo.TenantId > 0 ? await tenantManager.FindByIdAsync(user.TenantInfo.TenantId) : null; userDtos.Add(new UserDto { Id = user.Id, @@ -45,7 +65,7 @@ public class UserService( Email = user.Email, RealName = user.RealName, Phone = user.Phone, - TenantCode = user.TenantId.ToString(), + TenantCode = user.TenantInfo.TenantId.ToString(), TenantName = tenant?.Name ?? "", Roles = roles.ToList(), EmailConfirmed = user.EmailConfirmed, @@ -59,11 +79,11 @@ public class UserService( public async Task GetUserAsync(long id) { - var user = await repository.GetByIdAsync(id); + var user = await context.Users.FindAsync(id); if (user == null) return null; var roles = await userManager.GetRolesAsync(user); - var tenant = user.TenantId > 0 ? await tenantManager.FindByIdAsync(user.TenantId) : null; + var tenant = user.TenantInfo.TenantId > 0 ? await tenantManager.FindByIdAsync(user.TenantInfo.TenantId) : null; return new UserDto { Id = user.Id, @@ -71,7 +91,7 @@ public class UserService( Email = user.Email, RealName = user.RealName, Phone = user.Phone, - TenantCode = user.TenantId.ToString(), + TenantCode = user.TenantInfo.TenantId.ToString(), TenantName = tenant?.Name ?? "", Roles = roles.ToList(), EmailConfirmed = user.EmailConfirmed, @@ -82,25 +102,28 @@ public class UserService( public async Task CreateUserAsync(CreateUserDto dto) { - var tenantId = dto.TenantId.HasValue ? (int)dto.TenantId.Value : 0; Tenant? tenant = null; - if (tenantId != 0) + if (dto.TenantId.HasValue && dto.TenantId.Value > 0) { - tenant = await tenantManager.FindByIdAsync(tenantId); + tenant = await tenantManager.FindByIdAsync(dto.TenantId.Value); if (tenant == null) { throw new InvalidOperationException("Invalid tenant ID"); } } + var tenantInfo = tenant != null + ? new TenantInfo(tenant.Id, tenant.TenantCode, tenant.Name) + : new TenantInfo(0, "", ""); + var user = new ApplicationUser { UserName = dto.UserName, Email = dto.Email, RealName = dto.RealName, Phone = dto.Phone, - TenantId = tenant?.Id ?? 0, + TenantInfo = tenantInfo, EmailConfirmed = dto.EmailConfirmed, CreatedTime = DateTime.UtcNow }; @@ -139,7 +162,7 @@ public class UserService( Email = user.Email, RealName = user.RealName, Phone = user.Phone, - TenantCode = user.TenantId.ToString(), + TenantCode = user.TenantInfo.TenantId.ToString(), TenantName = tenant?.Name ?? "", Roles = roles.ToList(), EmailConfirmed = user.EmailConfirmed, @@ -150,7 +173,7 @@ public class UserService( public async Task UpdateUserAsync(long id, UpdateUserDto dto) { - var user = await repository.GetByIdAsync(id); + var user = await context.Users.FindAsync(id); if (user == null) { throw new KeyNotFoundException($"User with ID {id} not found"); @@ -164,6 +187,8 @@ public class UserService( user.EmailConfirmed = dto.EmailConfirmed; user.UpdatedTime = DateTime.UtcNow; + await userManager.UpdateAsync(user); + if (dto.IsActive) { await userManager.SetLockoutEnabledAsync(user, false); @@ -175,9 +200,7 @@ public class UserService( await userManager.SetLockoutEndDateAsync(user, DateTimeOffset.MaxValue); } - await context.SaveChangesAsync(); - - var tenant = user.TenantId > 0 ? await tenantManager.FindByIdAsync(user.TenantId) : null; + var tenant = user.TenantInfo.TenantId > 0 ? await tenantManager.FindByIdAsync(user.TenantInfo.TenantId) : null; await CreateAuditLog("user", "update", "User", user.Id, user.UserName, oldValue, System.Text.Json.JsonSerializer.Serialize(user)); @@ -189,7 +212,7 @@ public class UserService( Email = user.Email, RealName = user.RealName, Phone = user.Phone, - TenantCode = user.TenantId.ToString(), + TenantCode = user.TenantInfo.TenantId.ToString(), TenantName = tenant?.Name ?? "", Roles = roles.ToList(), EmailConfirmed = user.EmailConfirmed, @@ -219,7 +242,7 @@ public class UserService( public async Task DeleteUserAsync(long id) { - var user = await repository.GetByIdAsync(id); + var user = await context.Users.FindAsync(id); if (user == null) { throw new KeyNotFoundException($"User with ID {id} not found"); @@ -237,12 +260,12 @@ public class UserService( { var httpContext = httpContextAccessor.HttpContext; var userName = httpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier) ?? httpContext?.User?.Identity?.Name ?? "system"; - var tenantId = httpContext?.User?.FindFirstValue("TenantId"); + var tenantIdClaim = httpContext?.User?.FindFirstValue("TenantId"); var log = new AuditLog { Operator = userName, - TenantId = tenantId, + TenantId = tenantIdClaim, Operation = operation, Action = action, TargetType = targetType, diff --git a/Stores/ITenantStore.cs b/Stores/ITenantStore.cs deleted file mode 100644 index 6718f33..0000000 --- a/Stores/ITenantStore.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Fengling.Console.Models.Entities; -using Microsoft.AspNetCore.Identity; - -namespace Fengling.Console.Stores; - -public interface ITenantStore : IDisposable where TTenant : class -{ - Task FindByIdAsync(int tenantId, CancellationToken cancellationToken = default); - Task FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default); - Task> GetAllAsync(CancellationToken cancellationToken = default); - Task> GetPagedAsync(int page, int pageSize, string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default); - Task GetCountAsync(string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default); - Task CreateAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task UpdateAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task DeleteAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetUserCountAsync(int tenantId, CancellationToken cancellationToken = default); - - Task GetTenantCodeAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetNameAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetContactNameAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetContactEmailAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetContactPhoneAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetMaxUsersAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetDescriptionAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetStatusAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetExpiresAtAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetCreatedAtAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetUpdatedAtAsync(TTenant tenant, CancellationToken cancellationToken = default); - Task GetIsDeletedAsync(TTenant tenant, CancellationToken cancellationToken = default); - - Task SetTenantCodeAsync(TTenant tenant, string code, CancellationToken cancellationToken = default); - Task SetNameAsync(TTenant tenant, string name, CancellationToken cancellationToken = default); - Task SetContactNameAsync(TTenant tenant, string name, CancellationToken cancellationToken = default); - Task SetContactEmailAsync(TTenant tenant, string email, CancellationToken cancellationToken = default); - Task SetContactPhoneAsync(TTenant tenant, string? phone, CancellationToken cancellationToken = default); - Task SetMaxUsersAsync(TTenant tenant, int? maxUsers, CancellationToken cancellationToken = default); - Task SetDescriptionAsync(TTenant tenant, string? description, CancellationToken cancellationToken = default); - Task SetStatusAsync(TTenant tenant, TenantStatus status, CancellationToken cancellationToken = default); - Task SetExpiresAtAsync(TTenant tenant, DateTime? expiresAt, CancellationToken cancellationToken = default); - Task SetIsDeletedAsync(TTenant tenant, bool isDeleted, CancellationToken cancellationToken = default); -} diff --git a/Stores/TenantStore.cs b/Stores/TenantStore.cs deleted file mode 100644 index 2a3bccc..0000000 --- a/Stores/TenantStore.cs +++ /dev/null @@ -1,196 +0,0 @@ -using Fengling.Console.Datas; -using Fengling.Console.Models.Entities; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; - -namespace Fengling.Console.Stores; - -public class TenantStore : ITenantStore -{ - private readonly ApplicationDbContext _context; - private readonly DbSet _tenants; - - public TenantStore(ApplicationDbContext context) - { - _context = context; - _tenants = context.Tenants; - } - - public void Dispose() { } - - public virtual Task FindByIdAsync(int tenantId, CancellationToken cancellationToken = default) - { - return _tenants.FirstOrDefaultAsync(t => t.Id == tenantId, cancellationToken); - } - - public virtual Task FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default) - { - return _tenants.FirstOrDefaultAsync(t => t.TenantCode == tenantCode, cancellationToken); - } - - public virtual async Task> GetAllAsync(CancellationToken cancellationToken = default) - { - return (IList)await _tenants.ToListAsync(cancellationToken); - } - - public virtual async Task> GetPagedAsync(int page, int pageSize, string? name = null, - string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default) - { - var query = _tenants.AsQueryable(); - - if (!string.IsNullOrEmpty(name)) - query = query.Where(t => t.Name.Contains(name)); - - if (!string.IsNullOrEmpty(tenantCode)) - query = query.Where(t => t.TenantCode.Contains(tenantCode)); - - if (status.HasValue) - query = query.Where(t => t.Status == status); - - return await query - .OrderByDescending(t => t.CreatedAt) - .Skip((page - 1) * pageSize) - .Take(pageSize) - .ToListAsync(cancellationToken); - } - - public virtual async Task GetCountAsync(string? name = null, string? tenantCode = null, - TenantStatus? status = null, CancellationToken cancellationToken = default) - { - var query = _tenants.AsQueryable(); - - if (!string.IsNullOrEmpty(name)) - query = query.Where(t => t.Name.Contains(name)); - - if (!string.IsNullOrEmpty(tenantCode)) - query = query.Where(t => t.TenantCode.Contains(tenantCode)); - - if (status.HasValue) - query = query.Where(t => t.Status == status); - - return await query.CountAsync(cancellationToken); - } - - public virtual async Task CreateAsync(Tenant tenant, CancellationToken cancellationToken = default) - { - _tenants.Add(tenant); - await _context.SaveChangesAsync(cancellationToken); - return IdentityResult.Success; - } - - public virtual async Task UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default) - { - tenant.UpdatedAt = DateTime.UtcNow; - _tenants.Update(tenant); - await _context.SaveChangesAsync(cancellationToken); - return IdentityResult.Success; - } - - public virtual async Task DeleteAsync(Tenant tenant, CancellationToken cancellationToken = default) - { - _tenants.Remove(tenant); - await _context.SaveChangesAsync(cancellationToken); - return IdentityResult.Success; - } - - public virtual async Task GetUserCountAsync(int tenantId, CancellationToken cancellationToken = default) - { - return await _context.Users.CountAsync(u => u.TenantId == tenantId && !u.IsDeleted, cancellationToken); - } - - public virtual Task GetTenantCodeAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.TenantCode); - - public virtual Task GetNameAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.Name); - - public virtual Task GetContactNameAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.ContactName); - - public virtual Task GetContactEmailAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.ContactEmail); - - public virtual Task GetContactPhoneAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.ContactPhone); - - public virtual Task GetMaxUsersAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.MaxUsers); - - public virtual Task GetDescriptionAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.Description); - - public virtual Task GetStatusAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.Status); - - public virtual Task GetExpiresAtAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.ExpiresAt); - - public virtual Task GetCreatedAtAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.CreatedAt); - - public virtual Task GetUpdatedAtAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.UpdatedAt); - - public virtual Task GetIsDeletedAsync(Tenant tenant, CancellationToken cancellationToken = default) - => Task.FromResult(tenant.IsDeleted); - - public virtual Task SetTenantCodeAsync(Tenant tenant, string code, CancellationToken cancellationToken = default) - { - tenant.TenantCode = code; - return Task.CompletedTask; - } - - public virtual Task SetNameAsync(Tenant tenant, string name, CancellationToken cancellationToken = default) - { - tenant.Name = name; - return Task.CompletedTask; - } - - public virtual Task SetContactNameAsync(Tenant tenant, string name, CancellationToken cancellationToken = default) - { - tenant.ContactName = name; - return Task.CompletedTask; - } - - public virtual Task SetContactEmailAsync(Tenant tenant, string email, CancellationToken cancellationToken = default) - { - tenant.ContactEmail = email; - return Task.CompletedTask; - } - - public virtual Task SetContactPhoneAsync(Tenant tenant, string? phone, CancellationToken cancellationToken = default) - { - tenant.ContactPhone = phone; - return Task.CompletedTask; - } - - public virtual Task SetMaxUsersAsync(Tenant tenant, int? maxUsers, CancellationToken cancellationToken = default) - { - tenant.MaxUsers = maxUsers; - return Task.CompletedTask; - } - - public virtual Task SetDescriptionAsync(Tenant tenant, string? description, CancellationToken cancellationToken = default) - { - tenant.Description = description; - return Task.CompletedTask; - } - - public virtual Task SetStatusAsync(Tenant tenant, TenantStatus status, CancellationToken cancellationToken = default) - { - tenant.Status = status; - return Task.CompletedTask; - } - - public virtual Task SetExpiresAtAsync(Tenant tenant, DateTime? expiresAt, CancellationToken cancellationToken = default) - { - tenant.ExpiresAt = expiresAt; - return Task.CompletedTask; - } - - public virtual Task SetIsDeletedAsync(Tenant tenant, bool isDeleted, CancellationToken cancellationToken = default) - { - tenant.IsDeleted = isDeleted; - return Task.CompletedTask; - } -}