Пример #1
0
        public async Task <List <CriterionModel> > GetVendorCriteria()
        {
            var module = await _abstractTypesService.GetClientModule(BuType.Pg);

            var dictionaries = await _dictionaryService.GetDictionariesByNames(module.Id, new[]
            {
                Constants.DictionaryNames.CostType,
                Constants.DictionaryNames.ContentType,
                Constants.DictionaryNames.ProductionType
            });

            var result = new List <CriterionModel>
            {
                new CriterionModel
                {
                    FieldName = nameof(PgPaymentRule.BudgetRegion),
                    Values    = (await _regionsService.GetAsync()).ToDictionary(i => i.Key, i => i.Name),
                    Operators = new List <string> {
                        ExpressionType.Equal.ToString()
                    },
                    DefaultOperator = ExpressionType.Equal.ToString(),
                    Type            = CriterionType.Select
                },
                new CriterionModel
                {
                    FieldName = nameof(PgPaymentRule.CostType),
                    Values    = dictionaries.First(a => a.Name == Constants.DictionaryNames.CostType).DictionaryEntries.ToDictionary(i => i.Key, i => i.Value),
                    Operators = new List <string> {
                        ExpressionType.Equal.ToString()
                    },
                    DefaultOperator = ExpressionType.Equal.ToString(),
                    Type            = CriterionType.Select
                },
                new CriterionModel
                {
                    FieldName = nameof(PgPaymentRule.ContentType),
                    Values    = WithAllOption(dictionaries.First(a => a.Name == Constants.DictionaryNames.ContentType).DictionaryEntries.ToDictionary(i => i.Key, i => i.Value)),
                    Operators = new List <string> {
                        ExpressionType.Equal.ToString()
                    },
                    DefaultOperator = ExpressionType.Equal.ToString(),
                    Type            = CriterionType.Select
                },
                new CriterionModel
                {
                    FieldName = nameof(PgPaymentRule.ProductionType),
                    Values    = WithAllOption(dictionaries.First(a => a.Name == Constants.DictionaryNames.ProductionType).DictionaryEntries.ToDictionary(i => i.Key, i => i.Value)),
                    Operators = new List <string> {
                        ExpressionType.Equal.ToString()
                    },
                    DefaultOperator = ExpressionType.Equal.ToString(),
                    Type            = CriterionType.Select
                }
            };

            var aipeFeature = await _featureService.IsEnabled(core.Constants.Features.Aipe);

            if (aipeFeature != null && aipeFeature.Enabled)
            {
                result.Add(new CriterionModel
                {
                    FieldName = nameof(PgPaymentRule.IsAIPE),
                    Values    = new[] { true, false }.ToDictionary(v => v.ToString(), v => v.ToString()),
                    Operators = new List <string> {
                        ExpressionType.Equal.ToString()
                    },
                    DefaultOperator = ExpressionType.Equal.ToString(),
                    Type            = CriterionType.Select
                });
            }

            //Move total cost to last item as we don't want to change their orders in UI
            result.Add(new CriterionModel
            {
                FieldName = nameof(PgPaymentRule.TotalCostAmount),
                Operators = new List <string>
                {
                    ExpressionType.GreaterThanOrEqual.ToString(),
                    ExpressionType.GreaterThan.ToString()
                },
                DefaultOperator = ExpressionType.GreaterThanOrEqual.ToString(),
                Type            = CriterionType.Decimal
            });

            return(result);
        }