65 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C#
		
	
	
	
using langguanApi.Extensions.AutoDI;
 | 
						|
using langguanApi.Model;
 | 
						|
using langguanApi.Model.Entity;
 | 
						|
using System.Linq.Expressions;
 | 
						|
 | 
						|
namespace langguanApi.Service
 | 
						|
{
 | 
						|
    [ServiceInjection(InjectionType.Transient)]
 | 
						|
    public class RoleMenuServie : BaseService<RoleMenu>
 | 
						|
    {
 | 
						|
        public RoleMenuServie(IConfiguration config) : base(config, nameof(RoleMenu))
 | 
						|
        {
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 根据角色ID获取角色菜单
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="roleId"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        public async Task<List<RoleMenu>> GetByRoleId(string roleId)
 | 
						|
        {
 | 
						|
            Expression<Func<RoleMenu, bool>> exp = filter => filter.IsDelete == false && filter.RoleId == roleId;
 | 
						|
            return (await base.GetListWithExp(exp)).ToList();
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 表中添加角色菜单
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="input"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        public async Task<ApiResult> AddRoleMenu(AddRoleMenuDTO input)
 | 
						|
        {
 | 
						|
            foreach (var item in input.MenuIds)
 | 
						|
            {
 | 
						|
                await base.CreateAsync(new RoleMenu()
 | 
						|
                {
 | 
						|
                    RoleId = input.RoleId,
 | 
						|
                    MenuId = item
 | 
						|
                });
 | 
						|
            }
 | 
						|
            return new ApiResult() { code = 0 };
 | 
						|
        }
 | 
						|
        public async Task<ApiResult> DeleteRoleMenu(string roleId)
 | 
						|
        {
 | 
						|
            return null;
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 更新角色菜单
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="input"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        public async Task<ApiResult> UpdateRoleMenu(UpdateRoleMenuDTO input)
 | 
						|
        {
 | 
						|
            await base.BatchRemoveAsync(filter => filter.RoleId == input.RoleId);
 | 
						|
            foreach (var item in input.MenuIds)
 | 
						|
            {
 | 
						|
                await base.CreateAsync(new RoleMenu()
 | 
						|
                {
 | 
						|
                    RoleId = input.RoleId,
 | 
						|
                    MenuId = item
 | 
						|
                });
 | 
						|
            }
 | 
						|
            return new ApiResult() { code = 0 };
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |