コード例 #1
0
 /// <summary>
 /// 分配菜单功能
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public async Task <OperationResponse> AllocationMenuFunctionAsync(MenuFunctionInputDto input)
 {
     input.NotNull(nameof(input));
     return(await _menuFunctionRepository.UnitOfWork.UseTranAsync(async() =>
     {
         await _menuFunctionRepository.DeleteBatchAsync(x => x.MenuId == input.Id);
         await _menuFunctionRepository.InsertAsync(input.FuncIds.Select(x => new MenuFunctionEntity
         {
             MenuId = input.Id,
             FunctionId = x
         }).ToArray());
         return new OperationResponse(ResultMessage.AllocationSucces, OperationEnumType.Success);
     }));
 }
コード例 #2
0
        //private MenuFunction[] ToMenuFunctions(MenuFunctionInputDto menuFunctionInputDto)
        //{
        //    menuFunctionInputDto.NotNull(nameof(menuFunctionInputDto));
        //    menuFunctionInputDto.FunctionIds.NotNull("FunctionIds");
        //    return menuFunctionInputDto.FunctionIds.Select(f => new MenuFunction
        //    {

        //        FunctionId = f,
        //        MenuId = menuFunctionInputDto.MenuId
        //    }).ToArray();
        //}

        /// <summary>
        /// 批量删除功能菜单
        /// </summary>
        /// <param name="menuFunctionInputDto">输入DTO</param>
        /// <returns></returns>
        public async Task <OperationResponse> BatchDeleteMenuFunctionAsync(MenuFunctionInputDto menuFunctionInputDto)
        {
            menuFunctionInputDto.NotNull(nameof(menuFunctionInputDto));

            menuFunctionInputDto.FunctionIds.NotNull("FunctionIds");
            var functionIds = menuFunctionInputDto.FunctionIds;
            var menuId      = menuFunctionInputDto.MenuId;

            return(await _unitOfWork.UseTranAsync(async() =>
            {
                var count = await _menuFunctionRepository.DeleteBatchAsync(o => o.MenuId == menuId && functionIds.Contains(o.FunctionId));
                if (count <= 0)
                {
                    return new OperationResponse(OperationResponseType.NoChanged.ToDescription(), OperationResponseType.NoChanged);
                }
                return OperationResponse.Ok($"{count}个菜单功能删除成功!!!!");
            }));
        }