async Task ValidateAsync(Plan plan) { if (!plan.StartDate.HasValue) { ModelState.AddModelError("startDate", "必須填寫開始日期"); } else { if (plan.EndDate.HasValue) { if (plan.EndDate <= plan.StartDate) { ModelState.AddModelError("endDate", "結束日期錯誤"); } else { var existingPlans = (await _plansService.FetchAllAsync()).Where(x => x.Id != plan.Id).ToList(); var hasDateConflict = existingPlans.Where(x => x.HasDateConflict(plan)); if (hasDateConflict.HasItems()) { ModelState.AddModelError("endDate", "日期與其他方案衝突"); } } } } if (plan.Money < 150 || plan.Discount > 500) { ModelState.AddModelError("money", "金額錯誤"); } if (plan.Discount < 50 || plan.Discount > 95) { ModelState.AddModelError("discount", "折扣錯誤"); } }