Add inactive vehicle validation for base Log model, so that it triggers on import
This commit is contained in:
+12
-4
@@ -76,20 +76,28 @@ namespace MileageTraker.Web.Models
|
|||||||
if (LogType.Value == 0)
|
if (LogType.Value == 0)
|
||||||
yield return new ValidationResult("Required", new[] { "LogType" });
|
yield return new ValidationResult("Required", new[] { "LogType" });
|
||||||
|
|
||||||
|
using (var dataService = new DataService())
|
||||||
|
{
|
||||||
ValidationResult result = null;
|
ValidationResult result = null;
|
||||||
try
|
try
|
||||||
{
|
|
||||||
using (var dataService = new DataService())
|
|
||||||
{
|
{
|
||||||
dataService.ValidateOdometerChronology(VehicleId, EndOdometer, Date);
|
dataService.ValidateOdometerChronology(VehicleId, EndOdometer, Date);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (ChronologicalOrderException ex)
|
catch (ChronologicalOrderException ex)
|
||||||
{
|
{
|
||||||
result = new ValidationResult(ex.Message, new[] { "EndOdometer" });
|
result = new ValidationResult(ex.Message, new[] {"EndOdometer"});
|
||||||
}
|
}
|
||||||
if (result != null)
|
if (result != null)
|
||||||
yield return result;
|
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"});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user