using Hutopy.Application.Common.Interfaces; using Hutopy.Application.Common.Models; using Microsoft.AspNetCore.Identity; namespace Hutopy.Infrastructure.Identity; public class RoleService( RoleManager roleManager ) : IRoleService { public async Task CreateRoleAsync(string roleName) { var role = new ApplicationRole { Name = roleName, Id = Guid.NewGuid().ToString()}; var result = await roleManager.CreateAsync(role); return result.ToApplicationResult(); } public async Task DeleteRoleAsync(string roleName) { var role = new ApplicationRole { Name = roleName }; var result = await roleManager.DeleteAsync(role); return result.ToApplicationResult(); } public async Task FindRoleByIdAsync(string roleId) { var result = await roleManager.FindByIdAsync(roleId); if (result is null) return null; var roleModel = new RoleModel { Id = result.Id, Name = result.Name }; return roleModel; } public async Task FindRoleByNameAsync(string roleName) { var result = await roleManager.FindByNameAsync(roleName); if (result is null) return null; var roleModel = new RoleModel { Id = result.Id, Name = result.Name }; return roleModel; } }