You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

36 lines
1.1 KiB

using Easy;
using Easy.DDD.Domain;
using Easy.DDD.Domain.Repositories;
using Identity.Api.Clean.Domain.Entites;
using Identity.Api.Clean.Shared.IServices;
namespace Identity.Api.Clean.Domain.Services;
public class IdentityRoleManager : DomainService, IIdentityRoleManager
{
protected IRepository<IdentityRole> IdentityRoleRepository => LazyServiceProvider.LazyGetService<IRepository<IdentityRole>>();
protected virtual async Task ValidateNameAsync(string name, Guid? expectedId = null)
{
When.Is(string.IsNullOrEmpty(name), "角色名称不能为空");
var role = await IdentityRoleRepository.FirstOrDefaultAsync(o => o.RoleName == name);
When.Is(role != null && role.Id != expectedId, "重复的角色名称: " + name);
}
public async Task ChangeNameAsync(IdentityRole role, string roleName)
{
await ValidateNameAsync(roleName, role.Id);
role.SetName(roleName);
}
public async Task<IdentityRole> CreateAsync(string roleName, Guid tenantId)
{
await ValidateNameAsync(roleName);
return new IdentityRole(GuidGenerator.Create(), roleName, tenantId);
}
}