public bool HasForPast(int days, PeAuto_RuleTicketEvents4 sug, int minPriceDifference = -1, int maxPriceDifference = -1) { sug.CheckRequiredFields(price: false, sugPrice: false, runDate: true, eventDate: false); var minDate = sug.RunDate.Value.AddDays(-days); var suggestions = Data.Where(x => x.local_ticket_id == sug.local_ticket_id && x.Action == sug.Action && x.RunDate >= minDate && x.RunDate < sug.RunDate.Value) .OrderBy(x => x.RunDate) .ToList(); if (suggestions.Count < days) { return(false); } var i = 0; foreach (var curr in suggestions) { sug.CheckRequiredFields(price: true, sugPrice: true, runDate: true, eventDate: false); if (curr.RunDate != minDate.AddDays(i++)) { return(false); } var diff = curr.Price.Value - curr.SugPrice.Value; if (maxPriceDifference != -1) { if (sug.Action == SuggestionRulesStrings.Raise) { diff = curr.SugPrice.Value - curr.Price.Value; } if (diff < minPriceDifference || diff > maxPriceDifference) { return(false); } } else if (minPriceDifference != -1) { if (Math.Abs(diff) > minPriceDifference) { return(false); } } } return(true); }
public static bool ChangeHigher(this PeAuto_RuleTicketEvents4 sug, int price) { switch (sug.Action) { case SuggestionRulesStrings.Lower: return(sug.Price.Value - sug.SugPrice.Value > price); case SuggestionRulesStrings.Raise: return(sug.SugPrice.Value - sug.Price.Value > price); } throw new ArgumentException(nameof(sug.Action)); }
public void SaveResultToDatabase(PeAuto_RuleTicketEvents4 sug, bool runRule) { try { using (var context = new StnContext()) { var repo = new Repository(context); repo.ExecuteSqlCommand(@"EXEC [dbo].[pe_acceptSuggestion] @local_ticket_id = {0}, @RunDate = {1}, @RunRule = {2}, @Action = {3}, @Price = {4}", sug.local_ticket_id.Value, sug.RunDate.Value, runRule, sug.Action, sug.Price); } } catch (Exception ex) { const string message = "Error during saving sug to Dabatase."; throw new PriceEngineServiceSavingSuggestionException(sug.RunDate.Value, sug.local_ticket_id.Value, message + " Message: " + ex.Message); } }
public static void CheckRequiredFields(this PeAuto_RuleTicketEvents4 sug, bool price, bool sugPrice, bool runDate, bool eventDate) { if (price && !sug.Price.HasValue) { throw new ArgumentNullException(nameof(sug.Price)); } if (sugPrice && !sug.SugPrice.HasValue) { throw new ArgumentNullException(nameof(sug.SugPrice)); } if (runDate && !sug.RunDate.HasValue) { throw new ArgumentNullException(nameof(sug.RunDate)); } if (eventDate && !sug.Event_Date.HasValue) { throw new ArgumentNullException(nameof(sug.Event_Date)); } }
//Event_Date >= from and <= to public static bool EventDateFromTo(this PeAuto_RuleTicketEvents4 sug, int from, int to) { var nowDate = GetNowDate(); return(sug.Event_Date.Value.AddDays(-from) >= nowDate && sug.Event_Date.Value.AddDays(-to) <= nowDate); }
//Event_Date < 7 days public static bool EventDateWithin(this PeAuto_RuleTicketEvents4 sug, int days) { return(sug.Event_Date.Value.AddDays(-days) < GetNowDate()); }
public static void IncreasePrice(this PeAuto_RuleTicketEvents4 sug, int percentage) { double onePercentage = sug.Price.Value / 100.0; sug.Price += (int)Math.Round(onePercentage * percentage, 0); }
public void SaveResultToDatabase(PeAuto_RuleTicketEvents4 sug, bool runRule) { }