Validate new logs are not being entered after vehicle is inactive.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user