|
@@ -7,6 +7,8 @@ using Admin.Core.Service.Admin.Tenant.Input;
|
|
|
using Admin.Core.Service.Admin.Tenant.Output;
|
|
|
using Admin.Core.Common.Attributes;
|
|
|
using Admin.Core.Common.Helpers;
|
|
|
+using System.Linq;
|
|
|
+using System.Collections.Generic;
|
|
|
|
|
|
namespace Admin.Core.Service.Admin.Tenant
|
|
|
{
|
|
@@ -66,15 +68,16 @@ namespace Admin.Core.Service.Admin.Tenant
|
|
|
var tenant = await _tenantRepository.InsertAsync(entity);
|
|
|
|
|
|
var tenantId = tenant.Id;
|
|
|
- //添加角色
|
|
|
- var role = new RoleEntity { TenantId = tenantId, Code = "plat_admin", Name = "平台管理员", Enabled = true };
|
|
|
- await _roleRepository.InsertAsync(role);
|
|
|
|
|
|
//添加用户
|
|
|
var pwd = MD5Encrypt.Encrypt32("111111");
|
|
|
- var user = new UserEntity { TenantId = tenantId, UserName = input.Phone, NickName= input.RealName, Password = pwd, Status = 0 };
|
|
|
+ var user = new UserEntity { TenantId = tenantId, UserName = input.Phone, NickName = input.RealName, Password = pwd, Status = 0 };
|
|
|
await _userRepository.InsertAsync(user);
|
|
|
|
|
|
+ //添加角色
|
|
|
+ var role = new RoleEntity { TenantId = tenantId, Code = "plat_admin", Name = "平台管理员", Enabled = true };
|
|
|
+ await _roleRepository.InsertAsync(role);
|
|
|
+
|
|
|
//添加用户角色
|
|
|
var userRole = new UserRoleEntity() { UserId = user.Id, RoleId = role.Id };
|
|
|
await _userRoleRepository.InsertAsync(userRole);
|
|
@@ -105,26 +108,52 @@ namespace Admin.Core.Service.Admin.Tenant
|
|
|
return ResponseOutput.Ok();
|
|
|
}
|
|
|
|
|
|
+ [Transaction]
|
|
|
public async Task<IResponseOutput> DeleteAsync(long id)
|
|
|
{
|
|
|
- var result = false;
|
|
|
- if (id > 0)
|
|
|
- {
|
|
|
- result = (await _tenantRepository.DeleteAsync(m => m.Id == id)) > 0;
|
|
|
- }
|
|
|
+ //删除角色权限
|
|
|
+ await _rolePermissionRepository.Where(a => a.Role.TenantId == id).DisableGlobalFilter("Tenant").ToDelete().ExecuteAffrowsAsync();
|
|
|
|
|
|
- return ResponseOutput.Result(result);
|
|
|
+ //删除用户角色
|
|
|
+ await _userRoleRepository.Where(a => a.User.TenantId == id).DisableGlobalFilter("Tenant").ToDelete().ExecuteAffrowsAsync();
|
|
|
+
|
|
|
+ //删除用户
|
|
|
+ await _userRepository.Where(a => a.TenantId == id).DisableGlobalFilter("Tenant").ToDelete().ExecuteAffrowsAsync();
|
|
|
+
|
|
|
+ //删除角色
|
|
|
+ await _roleRepository.Where(a => a.TenantId == id).DisableGlobalFilter("Tenant").ToDelete().ExecuteAffrowsAsync();
|
|
|
+
|
|
|
+ //删除租户
|
|
|
+ await _tenantRepository.DeleteAsync(id);
|
|
|
+
|
|
|
+ return ResponseOutput.Ok();
|
|
|
}
|
|
|
|
|
|
+ [Transaction]
|
|
|
public async Task<IResponseOutput> SoftDeleteAsync(long id)
|
|
|
{
|
|
|
+ //删除用户
|
|
|
+ await _userRepository.SoftDeleteAsync(a => a.TenantId == id, "Tenant");
|
|
|
+
|
|
|
+ //删除角色
|
|
|
+ await _roleRepository.SoftDeleteAsync(a => a.TenantId == id, "Tenant");
|
|
|
+
|
|
|
+ //删除租户
|
|
|
var result = await _tenantRepository.SoftDeleteAsync(id);
|
|
|
|
|
|
return ResponseOutput.Result(result);
|
|
|
}
|
|
|
|
|
|
+ [Transaction]
|
|
|
public async Task<IResponseOutput> BatchSoftDeleteAsync(long[] ids)
|
|
|
{
|
|
|
+ //删除用户
|
|
|
+ await _userRepository.SoftDeleteAsync(a => ids.Contains(a.TenantId.Value), "Tenant");
|
|
|
+
|
|
|
+ //删除角色
|
|
|
+ await _roleRepository.SoftDeleteAsync(a => ids.Contains(a.TenantId.Value), "Tenant");
|
|
|
+
|
|
|
+ //删除租户
|
|
|
var result = await _tenantRepository.SoftDeleteAsync(ids);
|
|
|
|
|
|
return ResponseOutput.Result(result);
|