-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuleSetDeleter.cs
More file actions
49 lines (32 loc) · 1.1 KB
/
RuleSetDeleter.cs
File metadata and controls
49 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using EligibilityRuleEvaluator.Repositories;
using EligibilityRuleEvaluator.Rules;
namespace EligibilityRuleEvaluator {
public class RuleSetDeleter {
private readonly IEligibilityRepository _eligibilityRepository;
public RuleSetDeleter(IEligibilityRepository eligibilityRepository) {
if (eligibilityRepository == null)
throw new ArgumentNullException(nameof(eligibilityRepository));
_eligibilityRepository = eligibilityRepository;
}
public virtual void DeleteRootRuleSet(EligibilityRuleSet ruleSet) {
if (ruleSet == null)
throw new ArgumentNullException(nameof(ruleSet));
deleteRuleSet(ruleSet);
}
private void deleteRuleSet(EligibilityRuleSet ruleSet) {
foreach (var rule in ruleSet.Rules) {
deleteRule(rule);
}
foreach (var childRuleSet in ruleSet.ChildRuleSets) {
deleteRuleSet(childRuleSet);
}
_eligibilityRepository.DeleteRuleSet(ruleSet.Id);
}
private void deleteRule(IEligibilityRule rule) {
if (rule == null)
throw new ArgumentNullException(nameof(rule));
_eligibilityRepository.DeleteRule(rule.Id);
}
}
}