Add inactive vehicle validation for base Log model, so that it triggers on import

This commit is contained in:
2015-06-18 13:14:41 -04:00
parent 11c3b2c56b
commit 5198e4486f
+17 -9
View File
@@ -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;
}
}
}