first commit
This commit is contained in:
+80
@@ -0,0 +1,80 @@
|
||||
using FluentValidation;
|
||||
using Landmark.OLA.Models.Assets.Enums;
|
||||
using Landmark.OLA.Models.Loan.Enums;
|
||||
|
||||
namespace Landmark.OLA.Models.Loan.Validators
|
||||
{
|
||||
class VehicleValidator : AbstractValidator<LoanApplication>
|
||||
{
|
||||
private readonly Dictionary<VehicleType, List<LoanType>> _VehiclesToLoans = new()
|
||||
{
|
||||
{ VehicleType.Automobile,
|
||||
new List<LoanType>
|
||||
{
|
||||
LoanType.V_Vehicle,
|
||||
LoanType.V_VehiclePreapproval,
|
||||
}
|
||||
},
|
||||
{ VehicleType.Motorcycle,
|
||||
new List<LoanType>
|
||||
{
|
||||
LoanType.V_Vehicle,
|
||||
LoanType.V_VehiclePreapproval,
|
||||
}
|
||||
},
|
||||
{ VehicleType.Boat,
|
||||
new List<LoanType>
|
||||
{
|
||||
LoanType.M_Boat,
|
||||
}
|
||||
},
|
||||
{ VehicleType.ATV,
|
||||
new List<LoanType>
|
||||
{
|
||||
LoanType.P_Powersport,
|
||||
}
|
||||
},
|
||||
{ VehicleType.PWC,
|
||||
new List<LoanType>
|
||||
{
|
||||
LoanType.P_Powersport,
|
||||
}
|
||||
},
|
||||
{ VehicleType.RecreationalVehicle,
|
||||
new List<LoanType>
|
||||
{
|
||||
LoanType.P_Powersport,
|
||||
}
|
||||
},
|
||||
{ VehicleType.Snowmobile,
|
||||
new List<LoanType>
|
||||
{
|
||||
LoanType.P_Powersport,
|
||||
}
|
||||
},
|
||||
{ VehicleType.TrailerMotorHome,
|
||||
new List<LoanType>
|
||||
{
|
||||
LoanType.T_TrailerMotorhome,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
public VehicleValidator()
|
||||
{
|
||||
RuleFor(x => x.Vehicle.Type).Must((x, vehicleType) => IsAllowedVehicleTypeForLoan(x.LoanType.Value, vehicleType.Value))
|
||||
.WithMessage($"Vehicle type is not allowed for this loan type.");
|
||||
}
|
||||
|
||||
private bool IsAllowedVehicleTypeForLoan(LoanType loanType, VehicleType vehicleType)
|
||||
{
|
||||
if (_VehiclesToLoans.TryGetValue(vehicleType, out var loanTypeList))
|
||||
{
|
||||
return loanTypeList.Contains(loanType);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user