public static dynamic CheckWeekOfTheMonth(string WeekOfTheMonth, dynamic actualDueDateQuarter, bool returnDateTime) { string[] dueDateDetails = new string[2]; DateTime?dueDateDtT = null; switch (WeekOfTheMonth) { case "First": //First { if (returnDateTime) { dueDateDtT = actualDueDateQuarter.First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateQuarter.First()); if (!string.IsNullOrEmpty(dueDateDetails[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Second": //Second { if (returnDateTime) { dueDateDtT = actualDueDateQuarter.Skip(1).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateQuarter.Skip(1).First()); if (!string.IsNullOrEmpty(dueDateDetails[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Third": //Third { if (returnDateTime) { dueDateDtT = actualDueDateQuarter.Skip(2).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateQuarter.Skip(2).First()); if (!string.IsNullOrEmpty(dueDateDetails[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Fourth": //Fourth { if (returnDateTime) { dueDateDtT = actualDueDateQuarter.Skip(3).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateQuarter.Skip(3).First()); if (!string.IsNullOrEmpty(dueDateDetails[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Last": //Last { if (returnDateTime) { dueDateDtT = actualDueDateQuarter.Last(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateQuarter.Last()); if (!string.IsNullOrEmpty(dueDateDetails[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } } if (returnDateTime) { return(dueDateDtT); } else { return(dueDateDetails); } }
public static dynamic GetDueDate(int cycleTypeId, dynamic fileDueDate, string cycleInfo, bool returnDateTime) { string[] dueDateDetails = new string[2]; DateTime?dueDateDtT = null; // dueDateDetails[0] - dueDate // dueDateDetails[1] - Status switch (cycleTypeId) { case 1: // Quarterly int sourceMonthOftheCycleQuarter = ExtensionMethods.GetMonthNo(fileDueDate.MonthOftheCycle); int monthOftheCycleQuarter = 3 * (Convert.ToInt32(cycleInfo.Split('-')[1].Substring(cycleInfo.Split('-')[1].ToString().Length - 1)) - 1) + sourceMonthOftheCycleQuarter; var actualDueDateQuarter = ExtensionMethods.GetAllDatesInMonth(Convert.ToInt32(cycleInfo.Split('-')[0]), monthOftheCycleQuarter).Where(i => i.DayOfWeek.ToString() == fileDueDate.DayOfTheWeek); if (actualDueDateQuarter != null) { switch (fileDueDate.WeekOfTheMonth) { case "First": //First { if (returnDateTime) { dueDateDtT = actualDueDateQuarter.First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateQuarter.First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Second": //Second { if (returnDateTime) { dueDateDtT = actualDueDateQuarter.Skip(1).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateQuarter.Skip(1).First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Third": //Third { if (returnDateTime) { dueDateDtT = actualDueDateQuarter.Skip(2).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateQuarter.Skip(2).First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Fourth": //Fourth { if (returnDateTime) { dueDateDtT = actualDueDateQuarter.Skip(3).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateQuarter.Skip(3).First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Last": //Last { if (returnDateTime) { dueDateDtT = actualDueDateQuarter.Last(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateQuarter.Last()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } } } break; case 2: // Half yearly int sourceMonthOftheCycleHalfYearly = ExtensionMethods.GetMonthNo(fileDueDate.MonthOftheCycle); int monthOftheCycleHalfYearly = 3 * (Convert.ToInt32(cycleInfo.Split('-')[1].Substring(cycleInfo.Split('-')[1].ToString().Length - 1)) - 1) + sourceMonthOftheCycleHalfYearly; var actualDueDateHalfYearly = ExtensionMethods.GetAllDatesInMonth(Convert.ToInt32(cycleInfo.Split('-')[0]), monthOftheCycleHalfYearly).Where(i => i.DayOfWeek.ToString() == fileDueDate.DayOfTheWeek); if (actualDueDateHalfYearly != null) { switch (fileDueDate.WeekOfTheMonth) { case "First": //First { if (returnDateTime) { dueDateDtT = actualDueDateHalfYearly.First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateHalfYearly.First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Second": //Second { if (returnDateTime) { dueDateDtT = actualDueDateHalfYearly.Skip(1).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateHalfYearly.Skip(1).First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Third": //Third { if (returnDateTime) { dueDateDtT = actualDueDateHalfYearly.Skip(2).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateHalfYearly.Skip(2).First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Fourth": //Fourth { if (returnDateTime) { dueDateDtT = actualDueDateHalfYearly.Skip(3).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateHalfYearly.Skip(3).First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Last": //Last { if (returnDateTime) { dueDateDtT = actualDueDateHalfYearly.Last(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDateHalfYearly.Last()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } } } break; case 3: //yearly int sourceMonthOftheCycleYearly = ExtensionMethods.GetMonthNo(fileDueDate.MonthOftheCycle); var actualDueDate = ExtensionMethods.GetAllDatesInMonth(Convert.ToInt32(cycleInfo.Split('-')[0]), sourceMonthOftheCycleYearly).Where(i => i.DayOfWeek.ToString() == fileDueDate.DayOfTheWeek); if (actualDueDate != null) { switch (fileDueDate.WeekOfTheMonth) { case "First": //First { if (returnDateTime) { dueDateDtT = actualDueDate.First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDate.First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Second": //Second { if (returnDateTime) { dueDateDtT = actualDueDate.Skip(1).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDate.Skip(1).First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Third": //Third { if (returnDateTime) { dueDateDtT = actualDueDate.Skip(2).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDate.Skip(2).First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Fourth": //Fourth { if (returnDateTime) { dueDateDtT = actualDueDate.Skip(3).First(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDate.Skip(3).First()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } case "Last": //Last { if (returnDateTime) { dueDateDtT = actualDueDate.Last(); } else { string[] dueDate = ExtensionMethods.FormatDueDate(actualDueDate.Last()); if (!string.IsNullOrEmpty(dueDate[1])) { dueDateDetails[1] = dueDate[1].ToString(); } dueDateDetails[0] = dueDate[0].ToString(); } break; } } } break; default: throw new NotImplementedException(); } if (returnDateTime) { return(dueDateDtT); } else { return(dueDateDetails); } }