public void Execute() { _logger.Warning($"{_provider.Id}"); _avgBooking = GetAvgBooking(); if (_avgBooking.IsEmpty()) { // _logger.Warning( $"provider: {_provider}. No Data"); _avgBooking = new Booking { AmountBeforeTax = 19820, PrepaySum = 2644, RoomTypeCount = 1 }; } _logger.Info($"{_avgBooking}"); List <CancellationRule> cancellationRules = GetCancellationRules(); List <CancellationRulePenalty> result = new List <CancellationRulePenalty>(); int maxCancellationBeforeArrivalValue = GetMaxCancellationBeforeArrivalValue() + 1; // _logger.Info( $"MaxCancellationBeforeArrivalValue={maxCancellationBeforeArrivalValue}" ); CancellationRulePenaltyCalculator cancellationRulePenaltyCalculator = new CancellationRulePenaltyCalculator( _avgBooking, maxCancellationBeforeArrivalValue, _logger, _connectionString); foreach (CancellationRule cancellationRule in cancellationRules) { // _logger.Info( $"cancellation_rule: {cancellationRule}" ); decimal penalty = cancellationRulePenaltyCalculator.Calculate(cancellationRule); result.Add(new CancellationRulePenalty { CancellationRuleId = cancellationRule.Id, Penalty = penalty }); } List <int> sortedCancellationRuleIds = result.OrderByDescending(penalty => penalty.Penalty).Select(penalty => penalty.CancellationRuleId).ToList(); string rules = String.Empty; for (int index = 0; index < sortedCancellationRuleIds.Count; index++) { // _logger.Info($"cancellationRule: {cancellationRules.Find(rule => rule.Id == sortedCancellationRuleIds[ index ] )}, penalty={result.Find(cancellationRulePenalty => cancellationRulePenalty.CancellationRuleId == sortedCancellationRuleIds[ index ] ).Penalty}, priority: {index}"); SetCancellationRulePriority(sortedCancellationRuleIds[index], index); rules += $"{sortedCancellationRuleIds[index]} = {index} "; } _logger.Info(rules); }
public void Execute() { _avgBooking = GetAvgBooking(); if (_avgBooking.IsEmpty()) { _logger.Warning($"provider: {_provider}. No Data"); return; } _specialOffers = GetSpecialOffers(_provider.Id); _logger.Info($"provider: {_provider}. avg_booking: {_avgBooking}"); List <CancellationRule> cancellationRules = GetCancellationRules(); List <CancellationRulePenalty> result = new List <CancellationRulePenalty>(); int maxCancellationBeforeArrivalValue = GetMaxCancellationBeforeArrivalValue() + 1; _logger.Info($"MaxCancellationBeforeArrivalValue={maxCancellationBeforeArrivalValue}"); CancellationRulePenaltyCalculator cancellationRulePenaltyCalculator = new CancellationRulePenaltyCalculator(_avgBooking, maxCancellationBeforeArrivalValue, _specialOffers, _logger, _connectionString); foreach (CancellationRule cancellationRule in cancellationRules) { _logger.Info($"cancellation_rule: {cancellationRule}"); decimal penalty = cancellationRulePenaltyCalculator.Calculate(cancellationRule); result.Add(new CancellationRulePenalty { CancellationRuleId = cancellationRule.Id, Penalty = penalty }); } List <int> sortedCancellationRuleIds = result.OrderByDescending(penalty => penalty.Penalty).Select(penalty => penalty.CancellationRuleId).ToList(); _logger.Info(string.Empty); _logger.Info($"set priority for provider: {_provider}"); for (int index = 0; index < sortedCancellationRuleIds.Count; index++) { _logger.Info($"cancellationRule: {cancellationRules.Find(rule => rule.Id == sortedCancellationRuleIds[ index ] )}, penalty={result.Find(cancellationRulePenalty => cancellationRulePenalty.CancellationRuleId == sortedCancellationRuleIds[ index ] ).Penalty}, priority: {index}"); SetCancellationRulePriority(sortedCancellationRuleIds[index], index); } }