Beispiel #1
0
        /// <summary>
        /// Updates autopilot rules according to the rules repository changes
        /// </summary>
        /// <param name="ruleTypeId"></param>
        /// <param name="newRules"></param>
        /// <param name="deletedRules"></param>
        private void UpdateAutopilotRulesRepository(int ruleTypeId, IReadOnlyCollection <int> newRules, IReadOnlyCollection <int> deletedRules)
        {
            var flexibilityLevels = _flexibilityLevelRepository.GetAll().ToList();

            // delete autopilot rules
            if (deletedRules != null && deletedRules.Any())
            {
                var autopilotRulesToDelete = _autopilotRuleRepository.GetAll()
                                             .Where(rt => rt.RuleTypeId == ruleTypeId && deletedRules.Contains(rt.RuleId)).ToList();

                if (autopilotRulesToDelete.Any())
                {
                    _autopilotRuleRepository.Delete(autopilotRulesToDelete.Select(r => r.Id));
                }
            }

            // add new autopilot rules
            if (newRules != null && newRules.Any())
            {
                foreach (var ruleId in newRules)
                {
                    foreach (var flexibilityLevel in flexibilityLevels)
                    {
                        var autopilotRule = AutopilotRule.Create(flexibilityLevel.Id, ruleId, ruleTypeId);
                        _autopilotRuleRepository.Add(autopilotRule);
                    }
                }
            }

            _autopilotRuleRepository.SaveChanges();
        }
Beispiel #2
0
 public AutopilotRule Add(AutopilotRule model)
 {
     _repository.Add(model);
     return(model);
 }