Add inactive vehicle validation for base Log model, so that it triggers on import
This commit is contained in:
+17
-9
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user