//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}个菜单功能删除成功!!!!");
            }));
        }
Exemplo n.º 2
0
 public async Task <OperationResponse> UpdateAsync(MenuInputDto input)
 {
     input.NotNull(nameof(input));
     return(await _unitOfWork.UseTranAsync(async() =>
     {
         var result = await _menuRepository.UpdateAsync(input);
         await _menuFunction.DeleteBatchAsync(x => x.MenuId == input.Id);
         if (input.FunctionId?.Any() == true)
         {
             int count = await _menuFunction.InsertAsync(input.FunctionId.Select(x => new MenuFunction
             {
                 MenuId = input.Id,
                 FunctionId = x
             }).ToArray());
         }
         return new OperationResponse("保存成功", OperationResponseType.Success);
     }));
 }