/// <summary>
        /// 新增
        /// </summary>
        /// <param name="roleMenuRequestDto"></param>
        /// <returns></returns>
        public async Task <bool> CreateAsync(RoleMenuRequestDto roleMenuRequestDto)
        {
            var roleMenu = roleMenuRequestDto.MapToCreateEntity <RoleMenuRequestDto, RoleMenu>();
            await RoleMenuValidatorsFilter.DoValidationAsync(_roleMenuRespository, roleMenu, ValidatorTypeConstants.Create);

            return(await _roleMenuRespository.InsertAsync(roleMenu));
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="roleMenuRequestDto"></param>
        /// <returns></returns>
        public async Task <bool> ModifyAsync(RoleMenuRequestDto roleMenuRequestDto)
        {
            var roleMenu = await _roleMenuRespository.FirstOrDefaultAsync(e => e.Id == roleMenuRequestDto.Id);

            var entity = roleMenuRequestDto.MapToModifyEntity <RoleMenuRequestDto, RoleMenu>(roleMenu);
            await RoleMenuValidatorsFilter.DoValidationAsync(_roleMenuRespository, entity, ValidatorTypeConstants.Modify);

            return(await _roleMenuRespository.UpdateAsync(entity));
        }
Beispiel #3
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <JsonResponse> Modify(RoleMenuRequestDto input)
        {
            input.InitModifyRequest();
            var resJson = await _applicationEnginee.TryTransactionAsync(async() =>
            {
                await _roleMenuAppService.ModifyAsync(input);
            });

            return(resJson);
        }
        /// <summary>
        /// 获取某角色菜单权限
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <IList <PowerSelectViewResponse> > GetRoleMenu(RoleMenuRequestDto input)
        {
            var roleMenuDtos = await _roleMenuAppService.GetMenuByRoleIdsAsync(new List <string> {
                input.RoleId
            });

            return(roleMenuDtos.Select(o => new PowerSelectViewResponse {
                Id = o.MenuId
            }).ToList());
        }
        /// <summary>
        /// 保存角色菜单权限
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <JsonResponse> SaveRoleMenu(RoleMenuRequestDto input)
        {
            var result = await GetAddOrRemoveRoleMenuAction(input);

            var resJson = await _applicationEnginee.TryTransactionAsync(async() =>
            {
                await _roleMenuAppService.BatchCreateAsync(result.Item1);
                await _roleMenuAppService.BatchRemoveAsync(result.Item2);
            });

            return(resJson);
        }
Beispiel #6
0
 /// <summary>
 /// 获取某角色菜单权限
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public async Task <IList <PowerSelectViewResponse> > GetRoleMenu(RoleMenuRequestDto input)
 {
     return(await _menuDomainService.GetRoleMenu(input));
 }
Beispiel #7
0
 /// <summary>
 /// 保存角色菜单权限
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public async Task <JsonResponse> SaveRoleMenu(RoleMenuRequestDto input)
 {
     input.InitCreateRequest();
     input.InitModifyRequest();
     return(await _menuDomainService.SaveRoleMenu(input));
 }
        async Task <(IList <RoleMenuRequestDto>, IList <RoleMenuRequestDto>)> GetAddOrRemoveRoleMenuAction(RoleMenuRequestDto roleMenuRequestDto)
        {
            //查询该角色所有菜单
            var allExitsMenu = await _roleMenuAppService.GetMenuByRoleIdsAsync(new List <string> {
                roleMenuRequestDto.RoleId
            });

            var allExitsMenuIds = allExitsMenu.Select(m => m.MenuId).ToList();

            var addMenuIds = roleMenuRequestDto.MenuIds.Except(allExitsMenuIds);
            var delMenuIds = allExitsMenuIds.Except(roleMenuRequestDto.MenuIds);
            var addDto     = addMenuIds.Select(m => new RoleMenuRequestDto
            {
                Id             = Guid.NewGuid().ToString(),
                MenuId         = m,
                RoleId         = roleMenuRequestDto.RoleId,
                CreateUserId   = roleMenuRequestDto.CreateUserId,
                CreateUserName = roleMenuRequestDto.CreateUserName,
            });
            var delDto = delMenuIds.Select(m =>
                                           new RoleMenuRequestDto
            {
                MenuId         = m,
                RoleId         = roleMenuRequestDto.RoleId,
                IsDelete       = false,
                ModifyUserId   = roleMenuRequestDto.ModifyUserId,
                ModifyUserName = roleMenuRequestDto.ModifyUserName,
                ModifyDate     = DateTime.Now
            });

            return(addDto.ToList(), delDto.ToList());
        }