admin/src/SimpleAdmin.Api/Auth/CustomerRoleSeedContributor.cs
2026-06-10 17:57:43 +08:00

28 lines
769 B
C#

using Fake.Data.Seeding;
using Fake.Rbac.Application.Dtos.Role;
using Fake.Rbac.Application.Services;
namespace SimpleAdmin.Api.Auth;
public class CustomerRoleSeedContributor(RoleService roleService) : IDataSeedContributor
{
public const string CustomerRoleCode = "Customer";
public const string CustomerRoleName = "客户";
public async Task SeedAsync()
{
var roles = await roleService.GetAllRolesAsync();
if (roles.Any(x => string.Equals(x.Code, CustomerRoleCode, StringComparison.OrdinalIgnoreCase)))
{
return;
}
await roleService.CreateAsync(new RoleCreateDto
{
Code = CustomerRoleCode,
Name = CustomerRoleName,
Permissions = []
});
}
}