private Eligibility_Ruleset mapRuleSetToPoco(RuleContainer ruleContainer, SystemUser user, EligibilityRuleSet ruleSet, int? parentRuleSetId) { return new Eligibility_Ruleset { Eligibility_Type_Id = (int)ruleSet.EligibilityType, Rule_Container_Id = ruleContainer.Id, Created_By = user.Id, Date_Created = DateTime.Now, Is_Deleted = false, Ruleset_Aggregator_Id = (int)ruleSet.Aggregator, Parent_Ruleset_Id = parentRuleSetId }; }
public int SaveRule(SystemUser user, IEligibilityRule rule, int ruleSetId) { if (rule == null) throw new ArgumentNullException(nameof(rule)); var rulePoco = mapRuleToPoco(user, rule, ruleSetId); try { var ruleId = _eligibilityRepository.CreateRule(rulePoco); return ruleId; } catch (Exception e) { Console.WriteLine(e); throw; } }
private int saveRuleSet(RuleContainer customer, SystemUser user, EligibilityRuleSet ruleSet, int? parentRuleSetId) { var ruleSetPoco = mapRuleSetToPoco(customer, user, ruleSet, parentRuleSetId); var ruleSetId = _eligibilityRepository.CreateRuleSet(ruleSetPoco); foreach (var rule in ruleSet.Rules) { _ruleStorer.SaveRule(user, rule, ruleSetId); } foreach (var childRuleSet in ruleSet.ChildRuleSets) { saveRuleSet(customer, user, childRuleSet, ruleSetId); } return ruleSetId; }
private Eligibility_Rule mapRuleToPoco(SystemUser user, IEligibilityRule rule, int ruleSetId) { var rulePoco = rule.ConvertToEntity(); if (rulePoco.Eligibility_Rule_Type_Id == 0) { var ruleTypeName = rule.GetType().Name; var ruleType = _eligibilityRepository.GetRuleType(ruleTypeName); // NOTE: doesn't check for whether this rule type can be in this eligibility type. could potentially cause problems? if (ruleType == null) throw new Exception($"the rule type '{ruleTypeName}' was not found in the DB and so cannot be saved."); rulePoco.Eligibility_Rule_Type_Id = ruleType.Eligibility_Rule_Type_Id; } rulePoco.Date_Created = DateTime.Now; rulePoco.Is_Deleted = false; rulePoco.Created_By_Id = user.Id; rulePoco.Eligibility_Ruleset_Id = ruleSetId; return rulePoco; }
public virtual int SaveRootRuleSet(RuleContainer customer, SystemUser user, EligibilityRuleSet ruleSet) { if (customer == null) throw new ArgumentNullException(nameof(customer)); if (user == null) throw new ArgumentNullException(nameof(user)); if (ruleSet == null) throw new ArgumentNullException(nameof(ruleSet)); try { var ruleSetId = saveRuleSet(customer, user, ruleSet, null); return ruleSetId; } catch (Exception e) { Console.WriteLine(e); throw; } }