public async Task <OperationResponse> CreateAsync(MenuInputDto input) { input.NotNull(nameof(input)); return(await _unitOfWork.UseTranAsync(async() => { var result = await _menuRepository.InsertAsync(input); 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); })); }
/// <summary> /// 批量添加功能菜单 /// </summary> /// <param name="menuFunctionInputDto">输入DTO</param> /// <returns></returns> public async Task <OperationResponse> BatchAddMenuFunctionAsync(BatchAddMenuFunctionInputDto menuFunctionInputDto) { return(await _unitOfWork.UseTranAsync(async() => { List <MenuFunction> menuFunctions = new List <MenuFunction>(); foreach (var menuId in menuFunctionInputDto.MenuIds) { foreach (var functionId in menuFunctionInputDto.FunctionIds) { menuFunctions.Add(new MenuFunction() { MenuId = menuId, FunctionId = functionId }); } } var count = await _menuFunctionRepository.InsertAsync(menuFunctions.ToArray()); if (count <= 0) { return new OperationResponse(OperationResponseType.NoChanged.ToDescription(), OperationResponseType.NoChanged); } return OperationResponse.Ok($"{count}个菜单功能添加成功"); })); }