Exemplo n.º 1
0
        private static IEnumerable <AlertInterval> GetNotificationIntervals(int alertId)
        {
            IEnumerable <AlertInterval> intervals = new AlertInterval[] { };

            using (var conn = new SqlConnection(connectionStr))
            {
                intervals = conn.Query <AlertInterval>("[Alert].[GetNotificationIntervals]", new { @alertId = alertId }, commandType: System.Data.CommandType.StoredProcedure);
            }

            return(intervals);
        }
Exemplo n.º 2
0
        private void CalculateAlertScheduleSettingsForNextCall(AlertSchedule alert)
        {
            alert.LastCalled = DateTime.Now;
            if (!alert.IsOneTime)
            {
                if (alert.Intervals != null && alert.Intervals.Any())
                {
                    // first time emailing
                    if (alert.LastIntervalUsed == 0)
                    {
                        alert.LastIntervalUsed = alert.Intervals.Min(x => x.IntervalId);
                    }
                    else
                    {
                        alert.LastIntervalUsed = alert.Intervals.First(x => x.IntervalId == alert.LastIntervalUsed).NextIntervalId;
                    }

                    // calculate NextExecutingDate
                    AlertInterval currInterval = alert.Intervals.First(x => x.IntervalId == alert.LastIntervalUsed);
                    if (currInterval.WeekNumber.HasValue && currInterval.DayOfWeek.HasValue)
                    {
                        alert.NextExecutingDate = GetOrderedDateByCertainDayOfWeek(currInterval.WeekNumber.Value, currInterval.DayOfWeek.Value, currInterval.DurationMonths);
                    }
                    else if (currInterval.NextIntervalId == currInterval.IntervalId)
                    {
                        alert.NextExecutingDate = alert.LastCalled.AddDays(currInterval.DurationDays).AddMonths(currInterval.DurationMonths);
                    }
                    else
                    {
                        AlertInterval nextInterval = alert.Intervals.First(x => x.IntervalId == currInterval.NextIntervalId);
                        alert.NextExecutingDate = alert.LastCalled.AddDays(nextInterval.DurationDays).AddMonths(nextInterval.DurationMonths);
                    }
                }
            }
            AlertsRepository.UpdateNotificationSchedule(alert);
        }