39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using Dlhis.Entity.Sys.Entities;
|
|
using Dlhis.Sys.Identity.Request;
|
|
using Dlhis.Sys.Identity.Response;
|
|
using Kurisu.SqlSugar.Services;
|
|
|
|
namespace Dlhis.Sys.Identity.Services.Implements;
|
|
|
|
public class UserTenantService : IUserTenantService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public UserTenantService(IDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext.ChangeDb("identity");
|
|
}
|
|
|
|
public async Task<List<UserTenantResponse>> GetUserTenantsByIdAsync(int id)
|
|
{
|
|
return await _dbContext.Queryable<UserTenantEntity>()
|
|
.Where(x => x.UserId == id)
|
|
.Select(x => new UserTenantResponse
|
|
{
|
|
Code = x.TenantCode
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task SaveUserTenantsAsync(UserTenantSaveRequest request)
|
|
{
|
|
var userTenants = await _dbContext.Queryable<UserTenantEntity>().Where(x => x.UserId == request.UserId).ToListAsync();
|
|
await _dbContext.DeleteReallyAsync(userTenants);
|
|
|
|
await _dbContext.InsertAsync(request.TenantCodes.Select(x => new UserTenantEntity
|
|
{
|
|
UserId = request.UserId,
|
|
TenantCode = x
|
|
}).ToList());
|
|
}
|
|
} |