public static List <ScheduledPeriod> SchedulePeriods(ResolveSchedulingPeriodsRequest request) { var scheduledPeriods = new List <ScheduledPeriod>(); foreach (var period in request.SchedulingPeriods) { if (string.IsNullOrEmpty(period.MaximalLength)) { continue; } var startDate = GetPeriodDateTimeFromEvent(period.StartEvent, request); if (startDate.HasValue) { continue; } if (!string.IsNullOrEmpty(period.StartOffset)) { startDate += TimeSpan.Parse(period.StartOffset); } var endDate = startDate + TimeSpan.Parse(period.MaximalLength); scheduledPeriods.Add(new ScheduledPeriod { PeriodType = period.PeriodType, StartDate = startDate.Value, EndDate = endDate.Value }); } return(scheduledPeriods); }
private static DateTime?GetPeriodDateTimeFromEvent(LifecycleEvent @event, ResolveSchedulingPeriodsRequest request) { switch (@event) { case LifecycleEvent.RequestDate: return(request.RequestDate ?? request.CalculationDate); case LifecycleEvent.ContractSigned: return(request.SigningDate ?? (request.RequestDate ?? request.CalculationDate).Value.AddMonths(1)); case LifecycleEvent.Approved: return(request.ApprovalDate ?? (request.RequestDate ?? request.CalculationDate).Value.AddMonths(1)); case LifecycleEvent.FundsDisbursed: return(request.DisbursmentDate ?? (request.RequestDate ?? request.CalculationDate).Value.AddMonths(1)); case LifecycleEvent.FirstInstallmentDate: return(request.FirstInstallmentDate ?? (request.DisbursmentDate.HasValue ? (DateTime?)request.DisbursmentDate.Value.AddMonths(1) : null) ?? (request.RequestDate ?? request.CalculationDate).Value.AddMonths(2)); case LifecycleEvent.MaturityDate: return(request.MaturityDate ?? (request.DisbursmentDate.HasValue ? (DateTime?)request.DisbursmentDate.Value.AddMonths(12) : null) ?? (request.RequestDate ?? request.CalculationDate).Value.AddMonths(13)); default: return(null); } }