예제 #1
0
        public async Task Should_Clean_Value_Async()
        {
            var dynamicParameter = CreateAndGetDynamicParameterWithTestPermission();

            var dynamicParameterValue = new DynamicParameterValue()
            {
                DynamicParameterId = dynamicParameter.Id,
                Value    = "Test",
                TenantId = AbpSession.TenantId
            };

            var dynamicParameterValue2 = new DynamicParameterValue()
            {
                DynamicParameterId = dynamicParameter.Id,
                Value    = "Test2",
                TenantId = AbpSession.TenantId
            };

            await WithUnitOfWorkAsync(async() =>
            {
                await _dynamicParameterValueManager.AddAsync(dynamicParameterValue);
                await _dynamicParameterValueManager.AddAsync(dynamicParameterValue2);
            });

            await RunAndCheckIfPermissionControlledAsync(async() =>
            {
                await _dynamicParameterValueManager.CleanValuesAsync(dynamicParameter.Id);
            });

            await WithUnitOfWorkAsync(async() =>
            {
                var entity = await _dynamicParameterValueManager.GetAllValuesOfDynamicParameterAsync(dynamicParameter.Id);
                entity.ShouldBeEmpty();
            });
        }
예제 #2
0
        public async Task <GetAllEntityDynamicParameterValuesOutput> GetAllEntityDynamicParameterValues(GetAllEntityDynamicParameterValuesInput input)
        {
            var localCacheOfDynamicParameterValues = new Dictionary <int, List <string> >();

            async Task <List <string> > LocalGetAllValuesOfDynamicParameter(int dynamicParameterId)
            {
                if (!localCacheOfDynamicParameterValues.ContainsKey(dynamicParameterId))
                {
                    localCacheOfDynamicParameterValues[dynamicParameterId] = (await _dynamicParameterValueManager
                                                                              .GetAllValuesOfDynamicParameterAsync(dynamicParameterId))
                                                                             .Select(x => x.Value).ToList();
                }

                return(localCacheOfDynamicParameterValues[dynamicParameterId]);
            }

            var output = new GetAllEntityDynamicParameterValuesOutput();
            var entityDynamicParameters = await _entityDynamicParameterManager.GetAllAsync(input.EntityFullName);

            var entityDynamicParameterSelectedValues = (await _entityDynamicParameterValueManager.GetValuesAsync(input.EntityFullName, input.EntityId))
                                                       .GroupBy(value => value.EntityDynamicParameterId)
                                                       .ToDictionary(group => group.Key, items => items.ToList().Select(value => value.Value).ToList());

            foreach (var entityDynamicParameter in entityDynamicParameters)
            {
                var outputItem = new GetAllEntityDynamicParameterValuesOutputItem
                {
                    EntityDynamicParameterId = entityDynamicParameter.Id,
                    InputType             = _dynamicEntityParameterDefinitionManager.GetOrNullAllowedInputType(entityDynamicParameter.DynamicParameter.InputType),
                    ParameterName         = entityDynamicParameter.DynamicParameter.ParameterName,
                    AllValuesInputTypeHas = await LocalGetAllValuesOfDynamicParameter(entityDynamicParameter.DynamicParameter.Id),
                    SelectedValues        = entityDynamicParameterSelectedValues.ContainsKey(entityDynamicParameter.Id)
                        ? entityDynamicParameterSelectedValues[entityDynamicParameter.Id]
                        : new List <string>()
                };

                output.Items.Add(outputItem);
            }

            return(output);
        }