using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Shentun.Peis.Permissions; using Shentun.Peis.Rooms; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Identity; using Volo.Abp.ObjectExtending; namespace Shentun.Peis.Roles { /// /// 角色管理 /// [Authorize] public class MyRoleAppService : ApplicationService { private readonly IdentityRoleManager _roleManager; private readonly IIdentityRoleRepository _roleRepository; public MyRoleAppService( IdentityRoleManager roleManager, IIdentityRoleRepository roleRepository) { _roleManager = roleManager; _roleRepository = roleRepository; } /// /// 查询 /// /// [Authorize(PeisPermissions.SystemSettings.Default)] [HttpPost("api/app/MyRole/GetAllList")] public async Task> GetAllListAsync() { var list = await _roleRepository.GetListAsync(); return new ListResultDto( ObjectMapper.Map, List>(list) ); } /// /// 创建 /// /// /// [Authorize(PeisPermissions.SystemSettings.Default)] [HttpPost("api/app/MyRole/Create")] public async Task CreateAsync(IdentityRoleCreateDto input) { var role = new IdentityRole( GuidGenerator.Create(), input.Name, CurrentTenant.Id ) { IsDefault = input.IsDefault, IsPublic = input.IsPublic }; input.MapExtraPropertiesTo(role); (await _roleManager.CreateAsync(role)).CheckErrors(); await CurrentUnitOfWork.SaveChangesAsync(); return ObjectMapper.Map(role); } /// /// 修改 /// /// /// [Authorize(PeisPermissions.SystemSettings.Default)] [HttpPost("api/app/MyRole/Update")] public async Task UpdateAsync(UpdateRoleInputDto input) { var role = await _roleManager.GetByIdAsync(input.Id); role.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); (await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors(); role.IsDefault = input.IsDefault; role.IsPublic = input.IsPublic; input.MapExtraPropertiesTo(role); (await _roleManager.UpdateAsync(role)).CheckErrors(); await CurrentUnitOfWork.SaveChangesAsync(); return ObjectMapper.Map(role); } /// /// 删除 /// /// /// [Authorize(PeisPermissions.SystemSettings.Default)] [HttpPost("api/app/MyRole/Delete")] public async Task DeleteAsync(RoleIdInputDto input) { var role = await _roleManager.FindByIdAsync(input.Id.ToString()); if (role == null) { return; } (await _roleManager.DeleteAsync(role)).CheckErrors(); } [Authorize(PeisPermissions.SystemSettings.Default)] [RemoteService(false)] public async Task GetAsync(Guid id) { return ObjectMapper.Map( await _roleManager.GetByIdAsync(id) ); } [Authorize(PeisPermissions.SystemSettings.Default)] [RemoteService(false)] public async Task> GetListAsync(GetIdentityRolesInput input) { var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter); var totalCount = await _roleRepository.GetCountAsync(input.Filter); return new PagedResultDto( totalCount, ObjectMapper.Map, List>(list) ); } } }