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.
68 lines
2.6 KiB
68 lines
2.6 KiB
2 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Threading.Tasks;
|
||
|
using Microsoft.AspNetCore.Authorization;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using Omu.ValueInjecter;
|
||
|
using Volo.Abp.Application.Dtos;
|
||
|
using Volo.Abp.Application.Services;
|
||
|
using Volo.Abp.Identity;
|
||
|
|
||
|
namespace BaseService.UserManagement
|
||
|
{
|
||
|
[Route("api/[controller]/[action]")]
|
||
|
[Authorize(IdentityPermissions.Roles.Default)]
|
||
|
public class RoleAppService : ApplicationService
|
||
|
{
|
||
|
private IdentityRoleManager _roleManager { get; }
|
||
|
private IIdentityRoleRepository _repository { get; }
|
||
|
|
||
|
public RoleAppService(IdentityRoleManager roleManager, IIdentityRoleRepository roleRepository)
|
||
|
{
|
||
|
_roleManager = roleManager;
|
||
|
_repository = roleRepository;
|
||
|
}
|
||
|
|
||
|
[HttpGet]
|
||
|
public async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(GetIdentityRolesInput input)
|
||
|
{
|
||
|
var totalCount = await _repository.GetCountAsync(input.Filter).ConfigureAwait(false);
|
||
|
var items = await _repository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount,
|
||
|
input.Filter).ConfigureAwait(false);
|
||
|
var dtos = ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(items);
|
||
|
return new PagedResultDto<IdentityRoleDto>(totalCount, dtos);
|
||
|
}
|
||
|
|
||
|
[HttpPost]
|
||
|
[Authorize(IdentityPermissions.Roles.Create)]
|
||
|
public async Task<IdentityRoleDto> CreateAsync(IdentityRoleCreateDto input)
|
||
|
{
|
||
|
var role = new IdentityRole(GuidGenerator.Create(), input.Name);
|
||
|
role.InjectFrom(input);
|
||
|
await _roleManager.CreateAsync(role).ConfigureAwait(false);
|
||
|
var dto = ObjectMapper.Map<IdentityRole, IdentityRoleDto>(role);
|
||
|
return dto;
|
||
|
}
|
||
|
|
||
|
[HttpPut("{id}")]
|
||
|
[Authorize(IdentityPermissions.Roles.Update)]
|
||
|
public async Task<IdentityRoleDto> UpdateAsync(Guid id, IdentityRoleUpdateDto input)
|
||
|
{
|
||
|
var role = await _roleManager.GetByIdAsync(id).ConfigureAwait(false);
|
||
|
role.InjectFrom(input);
|
||
|
await _roleManager.UpdateAsync(role).ConfigureAwait(false);
|
||
|
var dto = ObjectMapper.Map<IdentityRole, IdentityRoleDto>(role);
|
||
|
return dto;
|
||
|
}
|
||
|
|
||
|
[HttpDelete("{id}")]
|
||
|
[Authorize(IdentityPermissions.Roles.Delete)]
|
||
|
public async Task<IActionResult> Delete(Guid id)
|
||
|
{
|
||
|
var role = await _roleManager.GetByIdAsync(id).ConfigureAwait(false);
|
||
|
await _roleManager.DeleteAsync(role).ConfigureAwait(false);
|
||
|
return new OkResult();
|
||
|
}
|
||
|
}
|
||
|
}
|