private IEnumerable <DateTime?> CalculateNextDeliveryDateTimes(int maxOccurences) { var retVal = new List <DateTime?>(); DateTime utcNow = _dateTimeUtcNow.UtcNow; //can not calculate a next delivery date if start or activate dates do not exist. if (!StartDateTime.HasValue && !ActivateDateTime.HasValue) { return(retVal); } //check if the stop date exists and has already passed. if (StopDateTime.HasValue && utcNow > StopDateTime.Value) { return(retVal); } //check if this is the first delivery if (utcNow <= ActivateDateTime.Value) { retVal.Add(ActivateDateTime.Value); return(retVal); } if (RepeatCode.GetValueOrDefault() == ScheduleRepeatCodes.Repeat) { //can not calculate nextDelivery if timeUnitcode is not set. if (!RepeatTimeUnitCode.HasValue) { return(null); } switch (RepeatTimeUnitCode.GetValueOrDefault()) { case ScheduleRepeatTimeUnitCodes.Hourly: return(CalculateHourlyNextDeliveryDateTimes(utcNow, maxOccurences)); case ScheduleRepeatTimeUnitCodes.Daily: return(CalculateDailyNextDeliveryDateTimes(utcNow, maxOccurences)); case ScheduleRepeatTimeUnitCodes.Weekly: return(CalculateWeeklyNextDeliveryDateTimes(utcNow, maxOccurences)); case ScheduleRepeatTimeUnitCodes.Monthly: return(CalculateMonthlyNextDeliveryDateTimes(utcNow, maxOccurences)); } } //not a repeated delivery, and the single delivery date has already passed. return(null); }
public RepeatCodeViewModel() { repeatCode = new RepeatCode(); Code = repeatCode.GenerateCode(); Coded = repeatCode.Code(); }