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.
|
|
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{ /// <summary>
/// 角色管理
/// </summary>
[Authorize] public class MyRoleAppService : ApplicationService {
private readonly IdentityRoleManager _roleManager; private readonly IIdentityRoleRepository _roleRepository;
public MyRoleAppService( IdentityRoleManager roleManager, IIdentityRoleRepository roleRepository) { _roleManager = roleManager; _roleRepository = roleRepository; }
/// <summary>
/// 查询
/// </summary>
/// <returns></returns>
[Authorize(PeisPermissions.SystemSettings.Default)] [HttpPost("api/app/MyRole/GetAllList")] public async Task<ListResultDto<IdentityRoleDto>> GetAllListAsync() { var list = await _roleRepository.GetListAsync(); return new ListResultDto<IdentityRoleDto>( ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(list) ); }
/// <summary>
/// 创建
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[Authorize(PeisPermissions.SystemSettings.Default)] [HttpPost("api/app/MyRole/Create")] public async Task<IdentityRoleDto> 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<IdentityRole, IdentityRoleDto>(role); }
/// <summary>
/// 修改
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[Authorize(PeisPermissions.SystemSettings.Default)] [HttpPost("api/app/MyRole/Update")] public async Task<IdentityRoleDto> 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<IdentityRole, IdentityRoleDto>(role); }
/// <summary>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[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<IdentityRoleDto> GetAsync(Guid id) { return ObjectMapper.Map<IdentityRole, IdentityRoleDto>( await _roleManager.GetByIdAsync(id) ); } [Authorize(PeisPermissions.SystemSettings.Default)] [RemoteService(false)] public async Task<PagedResultDto<IdentityRoleDto>> 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<IdentityRoleDto>( totalCount, ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(list) ); }
}}
|