Esempio n. 1
0
        private List <ScoringModel> GetScoringModels()
        {
            var               models = new List <ScoringModel>();
            EntitySchema      schema = UserConnection.EntitySchemaManager.GetInstanceByName("ScoringModel");
            EntitySchemaQuery esq    = new EntitySchemaQuery(schema);

            esq.PrimaryQueryColumn.IsAlwaysSelect = true;
            esq.IgnoreDisplayValues = true;
            esq.AddAllSchemaColumns();
            EntityCollection entityCollection = esq.GetEntityCollection(UserConnection);

            foreach (Entity scoringModelEntity in entityCollection)
            {
                ScoringModel model = CreateScoringModel(scoringModelEntity);
                models.Add(model);
            }
            return(models);
        }
Esempio n. 2
0
        private ScoringModel CreateScoringModel(Entity scoringModelEntity)
        {
            var          model                  = new ScoringModel();
            Guid         scoringObjectId        = scoringModelEntity.GetTypedColumnValue <Guid>("ScoringObjectId");
            Guid         columnUId              = scoringModelEntity.GetTypedColumnValue <Guid>("ColumnUId");
            EntitySchema scoringModelSchema     = UserConnection.EntitySchemaManager.GetInstanceByUId(scoringObjectId);
            string       scoringModelColumnName = scoringModelSchema.Columns.GetByUId(columnUId).Name;

            model.Rules             = new List <ScoringRule>();
            model.Id                = scoringModelEntity.PrimaryColumnValue;
            model.ModifiedOn        = scoringModelEntity.GetTypedColumnValue <DateTime>("ModifiedOn");
            model.IsActive          = scoringModelEntity.GetTypedColumnValue <bool>("IsActive");
            model.Name              = scoringModelEntity.GetTypedColumnValue <string>("Name");
            model.ScoringObjectId   = scoringObjectId;
            model.ScoringObjectName = scoringModelSchema.Name;
            model.ScoringColumnName = scoringModelColumnName;
            return(model);
        }
Esempio n. 3
0
        private ScoringRule CreateScoringRule(Entity scoringRuleEntity, ScoringModel scoringModel,
                                              RuleSerializationHelper ruleSerializationHelper)
        {
            var    rule         = new ScoringRule();
            string filterData   = scoringRuleEntity.GetTypedColumnValue <string>("FilterData");
            string ruleCriteria = ruleSerializationHelper.CreateRuleCriteria(filterData, scoringModel.ScoringObjectId,
                                                                             UserConnection);
            string ruleQuery = ruleSerializationHelper.CreateRuleCriteria(filterData, scoringModel.ScoringObjectId,
                                                                          UserConnection, true);

            rule.RuleCriteriaQuery = ruleQuery;
            rule.RuleCriteria      = ruleCriteria;
            rule.ScoringModelId    = scoringModel.Id;
            rule.Id            = scoringRuleEntity.GetTypedColumnValue <Guid>("Id");
            rule.ModifiedOn    = scoringRuleEntity.GetTypedColumnValue <DateTime>("ModifiedOn");
            rule.ScoringCount  = scoringRuleEntity.GetTypedColumnValue <int>("ScoringCount");
            rule.ScoringPoints = scoringRuleEntity.GetTypedColumnValue <decimal>("ScoringPoints");
            rule.Duration      = scoringRuleEntity.GetTypedColumnValue <int>("Duration");
            rule.Name          = scoringRuleEntity.GetTypedColumnValue <string>("Name");
            return(rule);
        }
Esempio n. 4
0
        private void ApplyScoringRules(List <ScoringModel> models)
        {
            var               ruleSerializationHelper = new RuleSerializationHelper();
            EntitySchema      scoringRuleSchema       = UserConnection.EntitySchemaManager.GetInstanceByName("ScoringRule");
            EntitySchemaQuery esq = new EntitySchemaQuery(scoringRuleSchema);

            esq.PrimaryQueryColumn.IsAlwaysSelect = true;
            esq.IgnoreDisplayValues = true;
            esq.AddAllSchemaColumns();
            EntityCollection entityCollection = esq.GetEntityCollection(UserConnection);

            foreach (Entity scoringRuleEntity in entityCollection)
            {
                Guid         scoringModelId = scoringRuleEntity.GetTypedColumnValue <Guid>("ScoringModelId");
                ScoringModel scoringModel   = models.FirstOrDefault(model => model.Id == scoringModelId);
                if (scoringModel != null)
                {
                    ScoringRule rule = CreateScoringRule(scoringRuleEntity, scoringModel, ruleSerializationHelper);
                    scoringModel.Rules.Add(rule);
                }
            }
        }