You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I want to define a role and assign a role to a user, what is the procedure? In which layer should I define the interfaces and services?
this is my code in ((Application)):
public CreateRoleCommandHandler(IRoleService roleService)
{
_roleService = roleService;
}
public async Task<bool> Handle(CreateRoleCommand request, CancellationToken cancellationToken)
{
var roleExists = await _roleService.RoleExistsAsync(request.RoleName);
if (roleExists)
{
throw new InvalidOperationException($"Role '{request.RoleName}' already exists.");
}
var result = await _roleService.CreateRoleAsync(request.RoleName);
if (!result)
{
throw new Exception($"Failed to create role '{request.RoleName}'.");
}
return true;
}
}`
and my code in((Infrastructure)):
`public class RoleService : IRoleService
{
private readonly RoleManager _roleManager;
public RoleService(RoleManager<IdentityRole> roleManager)
{
_roleManager = roleManager;
}
public async Task<bool> RoleExistsAsync(string roleName)
{
return await _roleManager.RoleExistsAsync(roleName);
}
public async Task<bool> CreateRoleAsync(string roleName)
{
var result = await _roleManager.CreateAsync(new IdentityRole(roleName));
return result.Succeeded;
}
}`
Is my path and method correct?
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
If I want to define a role and assign a role to a user, what is the procedure? In which layer should I define the interfaces and services?
this is my code in ((Application)):
`public class CreateRoleCommandHandler : IRequestHandler<CreateRoleCommand, bool>
{
private readonly IRoleService _roleService;
}`
and my code in((Infrastructure)):
`public class RoleService : IRoleService
{
private readonly RoleManager _roleManager;
}`
Is my path and method correct?
The text was updated successfully, but these errors were encountered: