예제 #1
0
        public async Task <string> CreateOperation(CreateOperationInput input)
        {
            input.CheckDataAnnotations().CheckValidResult();
            await _operationDomainService.Create(input);

            return("新增操作成功");
        }
예제 #2
0
        public async Task <string> CreateOperation(CreateOperationInput input)
        {
            var operation = await _permissionRepository.FirstOrDefaultAsync(p => p.Code == input.Code);

            if (operation != null)
            {
                throw new BusinessException($"系统中已经存在Code为{input.Code}的操作");
            }
            foreach (var funcId in input.FunctionIds)
            {
                var funcInfo = await _functionRepository.SingleOrDefaultAsync(p => p.Id == funcId);

                if (funcInfo == null)
                {
                    throw new BusinessException($"系统中不存在{funcId}的功能");
                }
            }
            operation = new Permission()
            {
                Code = input.Code,
                Name = input.Name,
                Memo = input.Memo,
                Mold = PermissionMold.Operate,
            };
            await _functionManager.CreateOperation(operation, input.FunctionIds);

            return($"新增{input.Name}操作成功");
        }
예제 #3
0
        public async Task <CreateOperationOutput> Create(CreateOperationInput input)
        {
            var exsitOperation = await _operationRepository.FirstOrDefaultAsync(p => p.Name == input.Name);

            if (exsitOperation != null)
            {
                throw new BusinessException($"系统中已经存在{input.Name}的操作,请勿重复添加");
            }
            var menu = await _menuRepository.SingleOrDefaultAsync(p => p.PermissionId == input.PermissionId);

            if (menu == null)
            {
                throw new BusinessException($"不存在PermissionId为{input.PermissionId}的菜单信息");
            }
            var operation  = input.MapTo <Operation>();
            var permission = input.MapTo <Permission>();

            var operationCount = await _operationRepository.GetCountAsync(p => p.MenuId == input.PermissionId);

            operation.Code  = menu.Code + HeroConstants.CodeRuleRestrain.CodeSeparator + (operationCount + 1).ToString().PadLeft(HeroConstants.CodeRuleRestrain.CodeCoverBit, HeroConstants.CodeRuleRestrain.CodeCoverSymbol);
            operation.Level = menu.Level + 1;

            await UnitOfWorkAsync(async (conn, trans) =>
            {
                var permissionId       = await _permissionRepository.InsertAndGetIdAsync(permission, conn, trans);
                operation.PermissionId = permissionId;
                operation.MenuId       = menu.Id;
                var operationId        = await _operationRepository.InsertAndGetIdAsync(operation, conn, trans);
                if (input.ActionIds != null && input.ActionIds.Any())
                {
                    foreach (var actionId in input.ActionIds)
                    {
                        var action = await _actionRepository.SingleOrDefaultAsync(p => p.Id == actionId);
                        if (action == null)
                        {
                            throw new BusinessException($"系统中不存在Id为{actionId}的方法");
                        }
                        var operationAction = new OperationActionRelation()
                        {
                            ActionId = actionId, OperationId = operationId, ServiceId = action.ServiceId
                        };
                        await _operationActionRepository.InsertAsync(operationAction, conn, trans);
                    }
                }
            }, Connection);

            return(new CreateOperationOutput()
            {
                Id = operation.Id, PermissionId = operation.PermissionId, Tips = "新增操作成功"
            });
        }
예제 #4
0
 public async Task <CreateOperationOutput> CreateOperation(CreateOperationInput input)
 {
     input.CheckDataAnnotations().CheckValidResult();
     return(await _operationDomainService.Create(input));
 }