From 5198e4486f8dc960a036080ab15ed614473c2f5d Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Thu, 18 Jun 2015 13:14:41 -0400 Subject: [PATCH] Add inactive vehicle validation for base Log model, so that it triggers on import --- Web/Models/Log.cs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Web/Models/Log.cs b/Web/Models/Log.cs index 51d964d..26626da 100644 --- a/Web/Models/Log.cs +++ b/Web/Models/Log.cs @@ -76,20 +76,28 @@ namespace MileageTraker.Web.Models if (LogType.Value == 0) yield return new ValidationResult("Required", new[] { "LogType" }); - ValidationResult result = null; - try + using (var dataService = new DataService()) { - using (var dataService = new DataService()) + ValidationResult result = null; + try { dataService.ValidateOdometerChronology(VehicleId, EndOdometer, Date); } + catch (ChronologicalOrderException ex) + { + result = new ValidationResult(ex.Message, new[] {"EndOdometer"}); + } + if (result != null) + yield return result; + + var inactiveDate = dataService.GetVehicle(VehicleId).InactiveDate; + if (inactiveDate.HasValue && Date.Date > inactiveDate) + { + yield return new ValidationResult( + string.Format("Vehicle was set inactive on {0:MM/dd/yyyy}", inactiveDate.Value), + new[] {"Date"}); + } } - catch (ChronologicalOrderException ex) - { - result = new ValidationResult(ex.Message, new[] { "EndOdometer" }); - } - if (result != null) - yield return result; } } } \ No newline at end of file