|
@@ -9,6 +9,7 @@ using System.Linq;
|
|
|
using System.Transactions;
|
|
|
using AutoMapper;
|
|
|
using GxPress.Request.Menu;
|
|
|
+using System.Transactions;
|
|
|
|
|
|
namespace GxPress.Service.Implement.Role
|
|
|
{
|
|
@@ -42,9 +43,27 @@ namespace GxPress.Service.Implement.Role
|
|
|
/// </summary>
|
|
|
/// <param name="models"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<bool> InsertSystemRoleAsync(Entity.SystemRole.SystemRole model)
|
|
|
+ public async Task<bool> InsertSystemRoleAsync(RoleInRequest request)
|
|
|
{
|
|
|
- return await systemRoleRepository.InsertAsync(model) > 0;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var transactionScope = new TransactionScope())
|
|
|
+ {
|
|
|
+ var role = new Entity.SystemRole.SystemRole();
|
|
|
+ role.Name = request.Name;
|
|
|
+ var roleId = await systemRoleRepository.InsertAsync(role);
|
|
|
+ var models = new SystemRoleMenusInRequest();
|
|
|
+ models.RoleId = roleId;
|
|
|
+ models.SystemRoleMenuInRequest = request.SystemRoleMenuInRequest;
|
|
|
+ await systemRoleMenusRepository.InsertAsync(models);
|
|
|
+ transactionScope.Complete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (System.Exception ex)
|
|
|
+ {
|
|
|
+ throw new Common.Exceptions.BusinessException(ex.Message);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
public async Task<IEnumerable<Entity.SystemRole.SystemRole>> GetSystemRoleAllAsync()
|
|
@@ -56,9 +75,27 @@ namespace GxPress.Service.Implement.Role
|
|
|
/// </summary>
|
|
|
/// <param name="model"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<bool> UpdateSystemRoleAsync(Entity.SystemRole.SystemRole model)
|
|
|
+ public async Task<bool> UpdateSystemRoleAsync(RoleInRequest request)
|
|
|
{
|
|
|
- return await systemRoleRepository.UpdateAsync(model);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var transactionScope = new TransactionScope())
|
|
|
+ {
|
|
|
+ var role = await systemRoleRepository.GetRoleAsync(request.Id);
|
|
|
+ role.Name = request.Name;
|
|
|
+ await systemRoleRepository.UpdateAsync(role);
|
|
|
+ var models = new SystemRoleMenusInRequest();
|
|
|
+ models.RoleId = request.Id;
|
|
|
+ models.SystemRoleMenuInRequest = request.SystemRoleMenuInRequest;
|
|
|
+ await systemRoleMenusRepository.InsertAsync(models);
|
|
|
+ transactionScope.Complete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (System.Exception ex)
|
|
|
+ {
|
|
|
+ throw new Common.Exceptions.BusinessException(ex.Message);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 删除权限
|
|
@@ -148,12 +185,18 @@ namespace GxPress.Service.Implement.Role
|
|
|
/// </summary>
|
|
|
/// <param name="roleId"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<IEnumerable<Entity.Menus.Menus>> GetMenusAllAsync(int roleId)
|
|
|
+ public async Task<List<MenuInRequest>> GetMenusAllAsync(int roleId)
|
|
|
{
|
|
|
//获取
|
|
|
var models = await systemRoleMenusRepository.GetAllAsync(roleId);
|
|
|
-
|
|
|
- return await menusRepository.GetAllAsync(models.Select(n => n.Id).ToList());
|
|
|
+ var item = await menusRepository.GetAllAsync(models.Select(n => n.Id).ToList());
|
|
|
+ var result = new List<MenuInRequest>();
|
|
|
+ result = item.Where(n => n.ParentId == 0).Select(n => _mapper.Map<MenuInRequest>(n)).ToList();
|
|
|
+ foreach (var request in result)
|
|
|
+ {
|
|
|
+ request.Children=item.Where(n => n.ParentId == request.Id).Select(n => _mapper.Map<MenuInRequest>(n)).ToList();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|