Validate new logs are not being entered after vehicle is inactive.

This commit is contained in:
2015-06-18 11:42:22 -04:00
parent 5d70617194
commit 11c3b2c56b
4 changed files with 39 additions and 25 deletions
+18 -10
View File
@@ -95,21 +95,29 @@ namespace MileageTraker.Web.ViewModels.CreateLog
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 odometerResult = null;
try
{
dataService.ValidateOdometerChronology(VehicleId, int.Parse(EndOdometer), Date);
}
catch (Exception ex)
{
odometerResult = new ValidationResult(ex.Message, new [] {"EndOdometer"});
}
if (odometerResult != null)
yield return odometerResult;
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 (Exception ex)
{
result = new ValidationResult(ex.Message, new [] {"EndOdometer"});
}
if (result != null)
yield return result;
}
public override string ToString()