123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using GxPress.Repository.Interface.SystemRoleMenus;
- using GxPress.Service.Interface.Role;
- using GxPress.Repository.Interface.SystemRole;
- using GxPress.Repository.Interface.Menus;
- using System.Threading.Tasks;
- using GxPress.Request.Role;
- using System.Collections.Generic;
- using System.Linq;
- using System.Transactions;
- using AutoMapper;
- namespace GxPress.Service.Implement.Role
- {
- public class RoleService : IRoleService
- {
- private readonly ISystemRoleMenusRepository systemRoleMenusRepository;
- private readonly IMenusRepository menusRepository;
- private readonly ISystemRoleRepository systemRoleRepository;
- private readonly IMapper _mapper;
- public RoleService(ISystemRoleMenusRepository systemRoleMenusRepository, IMenusRepository menusRepository, ISystemRoleRepository systemRoleRepository,IMapper _mapper)
- {
- this.systemRoleRepository = systemRoleRepository;
- this.systemRoleMenusRepository = systemRoleMenusRepository;
- this.menusRepository = menusRepository;
- this._mapper=_mapper;
- }
- /// <summary>
- /// 添加权限菜单关联
- /// </summary>
- /// <param name="models"></param>
- /// <returns></returns>
- public async Task<bool> InsertSystemRoleMenusAsync(SystemRoleMenusInRequest models)
- {
- return await systemRoleMenusRepository.InsertAsync(models);
- }
- /// <summary>
- /// 添加权限
- /// </summary>
- /// <param name="models"></param>
- /// <returns></returns>
- public async Task<bool> InsertSystemRoleAsync(Entity.SystemRole.SystemRole model)
- {
- return await systemRoleRepository.InsertAsync(model) > 0;
- }
- /// <summary>
- /// 修改权限
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public async Task<bool> UpdateSystemRoleAsync(Entity.SystemRole.SystemRole model)
- {
- return await systemRoleRepository.UpdateAsync(model);
- }
- /// <summary>
- /// 删除权限
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<bool> DeleteSystemRoleAsync(int id)
- {
- return await systemRoleRepository.DeleteAsync(id);
- }
- /// <summary>
- /// 添加菜单
- /// </summary>
- /// <param name="models"></param>
- /// <returns></returns>
- public async Task<bool> InsertMenusAsync(Entity.Menus.Menus model)
- {
- return await menusRepository.InsertAsync(model) > 0;
- }
- /// <summary>
- /// 添加菜单
- /// </summary>
- /// <param name="models"></param>
- /// <returns></returns>
- public async Task<bool> InsertMenusAsync(List<Entity.Menus.Menus> models)
- {
- try
- {
- using (var transactionScope = new TransactionScope())
- {
- foreach (var item in models)
- {
- var id = await menusRepository.InsertAsync(item);
- if (item.Children == null)
- continue;
- foreach (var menu in item.Children)
- {
- await menusRepository.InsertAsync(_mapper.Map<Entity.Menus.Menus>(menu));
- }
- }
- transactionScope.Complete();
- }
- }
- catch (System.Exception ex)
- {
- throw new Common.Exceptions.BusinessException(ex.Message);
- }
- return true;
- }
- /// <summary>
- /// 修改菜单
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public async Task<bool> UpdateMenusAsync(Entity.Menus.Menus model)
- {
- return await menusRepository.UpdateAsync(model);
- }
- /// <summary>
- /// 删除菜单
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<bool> DeleteMenusAsync(int id)
- {
- return await menusRepository.DeleteAsync(id);
- }
- /// <summary>
- /// 根据权限ID获取菜单
- /// </summary>
- /// <param name="roleId"></param>
- /// <returns></returns>
- public async Task<IEnumerable<Entity.Menus.Menus>> GetMenusAllAsync(int roleId)
- {
- //获取
- var models = await systemRoleMenusRepository.GetAllAsync(roleId);
- return await menusRepository.GetAllAsync(models.Select(n => n.Id).ToList());
- }
- /// <summary>
- /// 获取所有菜单
- /// </summary>
- /// <param name="roleId"></param>
- /// <returns></returns>
- public async Task<IEnumerable<Entity.Menus.Menus>> GetMenusAllAsync()
- {
- return await menusRepository.GetAllAsync();
- }
- }
- }
|