Validate new logs are not being entered after vehicle is inactive.
This commit is contained in:
@@ -59,7 +59,8 @@ namespace MileageTraker.Web.Models
|
|||||||
public string PurDate { get; set; }
|
public string PurDate { get; set; }
|
||||||
|
|
||||||
[DataType(DataType.DateTime)]
|
[DataType(DataType.DateTime)]
|
||||||
[DisplayFormat(NullDisplayText = "Currently Active", DataFormatString = @"{0:MM/dd/yyyy}")]
|
[DisplayFormat(NullDisplayText = "Currently Active", DataFormatString = @"{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
|
||||||
|
[InputSize("small")]
|
||||||
[FormatHint("mm/dd/yyyy")]
|
[FormatHint("mm/dd/yyyy")]
|
||||||
public DateTime? InactiveDate { get; set; }
|
public DateTime? InactiveDate { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
$('.enable-javascript').show();
|
$('.enable-javascript').show();
|
||||||
|
|
||||||
$("input#Date").datepicker({ maxDate: '+0d' });
|
$("input#Date, input#InactiveDate").datepicker({ maxDate: '+0d' });
|
||||||
|
|
||||||
$("input#CityName").autocomplete({
|
$("input#CityName").autocomplete({
|
||||||
source: "/City/Autocomplete",
|
source: "/City/Autocomplete",
|
||||||
|
|||||||
@@ -95,21 +95,29 @@ namespace MileageTraker.Web.ViewModels.CreateLog
|
|||||||
|
|
||||||
if (LogType.Value == 0)
|
if (LogType.Value == 0)
|
||||||
yield return new ValidationResult("Required", new[] { "LogType" });
|
yield return new ValidationResult("Required", new[] { "LogType" });
|
||||||
|
|
||||||
ValidationResult result = null;
|
using (var dataService = new DataService())
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using (var dataService = new DataService())
|
ValidationResult odometerResult = null;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
dataService.ValidateOdometerChronology(VehicleId, int.Parse(EndOdometer), Date);
|
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()
|
public override string ToString()
|
||||||
|
|||||||
@@ -124,27 +124,32 @@ namespace MileageTraker.Web.ViewModels.Log
|
|||||||
if (LogType.Value == 0)
|
if (LogType.Value == 0)
|
||||||
yield return new ValidationResult("Required", new[] { "LogType" });
|
yield return new ValidationResult("Required", new[] { "LogType" });
|
||||||
|
|
||||||
ValidationResult chronologyResult = null;
|
using (var dataService = new DataService())
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using (var dataService = new DataService())
|
ValidationResult chronologyResult = null;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
dataService.ValidateOdometerChronology(VehicleId, int.Parse(EndOdometer), Date);
|
dataService.ValidateOdometerChronology(VehicleId, int.Parse(EndOdometer), Date);
|
||||||
}
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
chronologyResult = new ValidationResult(ex.Message, new[] {"EndOdometer"});
|
||||||
chronologyResult = new ValidationResult(ex.Message, new [] {"EndOdometer"});
|
}
|
||||||
}
|
if (chronologyResult != null)
|
||||||
if (chronologyResult != null)
|
yield return chronologyResult;
|
||||||
yield return chronologyResult;
|
|
||||||
|
|
||||||
using (var dataService = new DataService())
|
|
||||||
{
|
|
||||||
var user = dataService.FindUserByFullName(UserFullName);
|
var user = dataService.FindUserByFullName(UserFullName);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
yield return new ValidationResult("User with this name doesn't exist", new[] { "UserFullName" });
|
yield return new ValidationResult("User with this name doesn't exist", new[] {"UserFullName"});
|
||||||
|
}
|
||||||
|
|
||||||
|
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