我創建了一個搗鼓你here
我會建議你做客戶端驗證也是如此。 我假設你的日期列表是爲了,所以第i個開始和結束日期的元素將代表第i個區間,因此只要日期是訂單東西的
//Checking to make sure all effective dates have end date, except the last one.
for (var i = 1; i < effectiveEndDates.Count; i++)
{
if (!effectiveEndDates[i - 1].HasValue)
{
result = "cannot have a previous billing address without and end date.";
}
}
//Ensure all the startDates Dates are on or after the next end Date
//This solution will work if the effective dates are in order.
for (var i = 1; i < effectiveStartDates.Count; i++)
{
var effectiveEndDate = effectiveEndDates[i - 1];
if (effectiveEndDate != null && effectiveEndDate.Value > effectiveStartDates[i])
{
result = "cannot have 2 active billing address.";
}
}
行會做的伎倆(如生效日期)。希望這可以幫助
更新:我更新了小提琴,以確保沒有任何重疊的無限範圍。 [檢查這個](https://dotnetfiddle.net/nmyA3P)
你有效的地址日期爲了 – SadiRubaiyet