完善菜单接口
This commit is contained in:
@@ -26,7 +26,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
[HttpGet]
|
||||
public async Task<Result> GetMenu()
|
||||
{
|
||||
return Result.Success().SetData(await _menuService.GetTopMenu());
|
||||
//var top =await _menuService.GetTopMenu();
|
||||
//var children=await _menuService.get
|
||||
return Result.Success().SetData(await _menuService.GetTopMenu());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -71,10 +71,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
[HttpPost]
|
||||
public async Task<Result> SetMenuByRole(IdsListDto<int> idsListDto)
|
||||
{
|
||||
foreach(var id in idsListDto.ids1)
|
||||
{
|
||||
await _roleService.SetMenusByRolesId(idsListDto.ids2, id);
|
||||
}
|
||||
await _roleService.SetMenusByRolesId(idsListDto.ids2, idsListDto.ids1);
|
||||
return Result.Success();
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -60,5 +60,6 @@ namespace Yi.Framework.Interface
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<menu>> GetChildrenMenu(menu _menu);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="menuIds"></param>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> SetMenusByRolesId(List<int> menuIds, int roleId);
|
||||
Task<bool> SetMenusByRolesId(List<int> menuIds, List<int> roleIds);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ namespace Yi.Framework.Service
|
||||
{
|
||||
public MenuService(DbContext Db) : base(Db) { }
|
||||
|
||||
|
||||
public async Task<menu> AddChildrenMenu(menu _menu, menu _children)
|
||||
{
|
||||
var menu_data = await _Db.Set<menu>().Include(u => u.children).Where(u => u.id == _menu.id).FirstOrDefaultAsync();
|
||||
_children.is_top = (short)Common.Enum.TopFlagEnum.Children;
|
||||
_children.is_top = (short)Common.Enum.TopFlagEnum.Children;
|
||||
menu_data.children.Add(_children);
|
||||
await UpdateAsync(menu_data);
|
||||
return menu_data;
|
||||
|
||||
@@ -42,17 +42,20 @@ namespace Yi.Framework.Service
|
||||
return role_data.users.ToList();
|
||||
}
|
||||
|
||||
public async Task<bool> SetMenusByRolesId(List<int> menuIds, int roleId)
|
||||
public async Task<bool> SetMenusByRolesId(List<int> menuIds,List<int> roleIds)
|
||||
{
|
||||
var role_data = await GetEntity(u => u.id == roleId && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
var role_data = await _Db.Set<role>().Include(u=>u.menus)
|
||||
.Where(u =>roleIds.Contains(u.id) && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
if (role_data == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var menuList = await _Db.Set<menu>().Where(u => menuIds.Contains(u.id)&&u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
|
||||
role_data.menus =menuList;
|
||||
return await AddAsync(role_data);
|
||||
foreach(var role in role_data)
|
||||
{
|
||||
role.menus =menuList;
|
||||
}
|
||||
return await UpdateListAsync(role_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user