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> 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>(items); return new PagedResultDto(totalCount, dtos); } [HttpPost] [Authorize(IdentityPermissions.Roles.Create)] public async Task CreateAsync(IdentityRoleCreateDto input) { var role = new IdentityRole(GuidGenerator.Create(), input.Name); role.InjectFrom(input); await _roleManager.CreateAsync(role).ConfigureAwait(false); var dto = ObjectMapper.Map(role); return dto; } [HttpPut("{id}")] [Authorize(IdentityPermissions.Roles.Update)] public async Task 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(role); return dto; } [HttpDelete("{id}")] [Authorize(IdentityPermissions.Roles.Delete)] public async Task Delete(Guid id) { var role = await _roleManager.GetByIdAsync(id).ConfigureAwait(false); await _roleManager.DeleteAsync(role).ConfigureAwait(false); return new OkResult(); } } }