Пример #1
0
        public virtual ActionResult RulesCreateAndEdit(
            int idRule            = 0,
            string module         = "",
            string classification = "")
        {
            var response = new RuleEngViewModel
            {
                Description         = string.Empty,
                Classification      = string.Empty,
                ClassificationId    = 0,
                Code                = string.Empty,
                CodeId              = 0,
                GroupRule           = string.Empty,
                IsActive            = true,
                Module              = string.Empty,
                ModuleId            = 0,
                Name                = string.Empty,
                Order               = 0,
                Priority            = 0,
                Result              = string.Empty,
                RuleEngId           = 0,
                RuleId              = idRule,
                SerializedViewModel = string.Empty,
                RuleEngCondition    = new List <RuleEngConditionViewModel>(),
                RuleEngResult       = new List <RuleEngResultViewModel>()
            };

            if (idRule != 0)
            {
                response = _ruleEngService.GetRulesCreateAndEdit(idRule, module).GetRuleEng;
            }

            response.RuleGroupModule = _ruleEngService.GetRuleEngGroups().GetRuleEngGroup;
            response.Source          =
                _ruleEngService.GetItemsGroup(0, RulesEngAttributes.SOURCE).GetRuleEngGroup;
            ViewBag.fixLoad              = RulesEngAttributes.RESPONSE_TRUE;
            response.MaxOrder            = idRule != 0 ? _ruleEngService.GetRuleId(idRule) : 1;
            response.SerializedViewModel = PageSerializationHelper
                                           .SerializeObject(response);

            return(PartialView("Partials/RulesEdit", response));
        }
Пример #2
0
        public static void UpdateRuleEngViewModel(
            this RuleEngViewModel viewModel,
            ClientFieldData[] clientFieldData)
        {
            var searchModule =
                clientFieldData.FirstOrDefault(o =>
                                               !string.IsNullOrWhiteSpace(o.Name) && o.Name.Equals(SEARCH_RULE_MODULE));

            if (searchModule != null)
            {
                viewModel.ModuleId = Convert.ToInt32(searchModule.Value);
            }

            var ruleCode =
                clientFieldData.FirstOrDefault(o =>
                                               !string.IsNullOrWhiteSpace(o.Name) && o.Name.Equals(SEARCH_RULE_CODE));

            if (ruleCode != null)
            {
                viewModel.Code = ruleCode.Value;
            }

            var ruleName =
                clientFieldData.FirstOrDefault(o =>
                                               !string.IsNullOrWhiteSpace(o.Name) && o.Name.Equals(SEARCH_RULE_NAME));

            if (ruleName != null)
            {
                viewModel.Name = ruleName.Value;
            }

            var ruleDescription =
                clientFieldData.FirstOrDefault(o =>
                                               !string.IsNullOrWhiteSpace(o.Name) && o.Name.Equals(SEARCH_RULE_DESCRIPTION));

            if (ruleDescription != null)
            {
                viewModel.Description = ruleDescription.Value;
            }

            var isActive = clientFieldData.FirstOrDefault(o =>
                                                          !string.IsNullOrWhiteSpace(o.Name) && o.Name.Equals(ACTIVE_RE));

            if (isActive != null)
            {
                viewModel.IsActive = Convert.ToBoolean(isActive.Value);
            }

            var conditionIdValue = clientFieldData
                                   .Where(o => o.Name.Equals(CONDITION_ID_VALUE))
                                   .ToList();
            var ruleOrderIdValue = clientFieldData
                                   .Where(o => o.Name.Equals(RULE_ORDER))
                                   .ToList();
            var elementValue = clientFieldData
                               .Where(o => o.Name.Equals(ELEMENT_CONDITION))
                               .ToList();
            var settingValue = clientFieldData
                               .Where(o => o.Name.Equals(SETTING_CONDITION))
                               .ToList();
            var settingNameValue = clientFieldData
                                   .Where(o => o.Name.Equals(SETTING_NAME_CONDITION))
                                   .ToList();
            var activeValue = clientFieldData
                              .Where(o => o.Name.Equals(ACTIVE))
                              .ToList();
            var groupIdValue = clientFieldData
                               .Where(o => o.Name.Equals(RULE_GROUP_NUMBER))
                               .ToList();
            var isNotValue = clientFieldData
                             .Where(o => o.Name.Equals(IS_NOT))
                             .ToList();

            viewModel.RuleEngCondition = (
                from conditionId in conditionIdValue
                join ruleOrderId in ruleOrderIdValue
                on conditionIdValue.IndexOf(conditionId)
                equals ruleOrderIdValue.IndexOf(ruleOrderId)
                join element in elementValue
                on conditionIdValue.IndexOf(conditionId)
                equals elementValue.IndexOf(element)
                join setting in settingValue
                on conditionIdValue.IndexOf(conditionId)
                equals settingValue.IndexOf(setting)
                join settingName in settingNameValue
                on conditionIdValue.IndexOf(conditionId)
                equals settingNameValue.IndexOf(settingName)
                join active in activeValue
                on conditionIdValue.IndexOf(conditionId)
                equals activeValue.IndexOf(active)
                join groupId in groupIdValue
                on conditionIdValue.IndexOf(conditionId)
                equals groupIdValue.IndexOf(groupId)
                join isNot in isNotValue
                on conditionIdValue.IndexOf(conditionId)
                equals isNotValue.IndexOf(isNot)
                select new RuleEngConditionViewModel
            {
                ConditionId = int.Parse(conditionId.Value),
                Order = int.Parse(ruleOrderId.Value),
                Element = element.Value,
                Value = setting.Value,
                Description = settingName.Value,
                IsActive = bool.Parse(active.Value),
                GroupNumber = int.Parse(groupId.Value),
                IsNot = bool.Parse(isNot.Value)
            }).ToList();
        }