205 lines
6.7 KiB
C#
205 lines
6.7 KiB
C#
using FluentValidation;
|
|
using FluentValidation.Results;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace ReserveManagementSystemLib.Models
|
|
{
|
|
public class Loan
|
|
{
|
|
[Key]
|
|
public int LoanId { get; set; }
|
|
|
|
public int ImportId { get; set; }
|
|
|
|
public string MemberNumber { get; set; }
|
|
|
|
public string LoanNumber { get; set; }
|
|
|
|
public string MemberLastName { get; set; }
|
|
|
|
public string MemberFirstName { get; set; }
|
|
|
|
public string MemberInitial { get; set; }
|
|
|
|
public string DealerOrganizationNumber { get; set; }
|
|
|
|
public DateTime LoanDate { get; set; }
|
|
|
|
public DateTime PostedDate { get; set; }
|
|
|
|
public DateTime FirstPmtDate { get; set; }
|
|
|
|
public DateTime FinalPmtDate { get; set; }
|
|
|
|
public decimal LoanAmount { get; set; }
|
|
|
|
public decimal BuyRate { get; set; }
|
|
|
|
public decimal ContractRate { get; set; }
|
|
|
|
public decimal MonthlyPmt { get; set; }
|
|
|
|
public string LoanTypeId { get; set; }
|
|
|
|
public int Term { get; set; }
|
|
|
|
public decimal ReserveAmount { get; set; }
|
|
|
|
public bool FlatFeePaid { get; set; }
|
|
|
|
public decimal? ChargeBack { get; set; }
|
|
|
|
public string ChargebackMessage { get; set; }
|
|
|
|
public byte? RemainingMonthsAtClose { get; set; }
|
|
|
|
public DateTime? PaidLoanDate { get; set; }
|
|
|
|
public string ReserveMessage { get; set; }
|
|
|
|
public bool ActionRequired { get; set; }
|
|
|
|
public DateTime? StatementDate { get; set; }
|
|
|
|
public decimal? Adjustment { get; set; }
|
|
|
|
public string LoanStatus { get; set; }
|
|
|
|
public DateTime? ExportedReserveDate { get; set; }
|
|
|
|
public DateTime? ExportedChargebackDate { get; set; }
|
|
|
|
public string ApplicationId { get; set; }
|
|
|
|
public bool Warranty { get; set; }
|
|
|
|
public bool Gap { get; set; }
|
|
|
|
public bool CreditLife { get; set; }
|
|
|
|
public bool CreditDisability { get; set; }
|
|
|
|
public bool Mbp { get; set; }
|
|
|
|
public string AccountType { get; set; }
|
|
|
|
[ForeignKey("DealerOrganizationNumber")]
|
|
public Dealer Dealer { get; set; }
|
|
|
|
[ForeignKey("LoanTypeId")]
|
|
public LoanType LoanType { get; set; }
|
|
|
|
public Vehicle Vehicle { get; set; }
|
|
|
|
[NotMapped]
|
|
public List<ValidationFailure> ValidationErrors { get; set; }
|
|
|
|
public bool HasSameReserve(object obj)
|
|
{
|
|
return obj is Loan loan &&
|
|
LoanDate == loan.LoanDate &&
|
|
Term == loan.Term &&
|
|
FirstPmtDate == loan.FirstPmtDate &&
|
|
FinalPmtDate == loan.FinalPmtDate &&
|
|
LoanAmount == loan.LoanAmount &&
|
|
LoanTypeId == loan.LoanTypeId &&
|
|
BuyRate == loan.BuyRate &&
|
|
ContractRate == loan.ContractRate;
|
|
}
|
|
|
|
public bool IsBoatLoan(object obj)
|
|
{
|
|
return obj is Loan loan &&
|
|
AccountType == "DL09" || AccountType == "DL10" || AccountType == "DL11" || AccountType == "DL12";
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return obj is Loan loan &&
|
|
MemberNumber == loan.MemberNumber &&
|
|
LoanNumber == loan.LoanNumber &&
|
|
MemberLastName == loan.MemberLastName &&
|
|
MemberFirstName == loan.MemberFirstName &&
|
|
MemberInitial == loan.MemberInitial &&
|
|
DealerOrganizationNumber == loan.DealerOrganizationNumber &&
|
|
LoanDate == loan.LoanDate &&
|
|
PostedDate == loan.PostedDate &&
|
|
Term == loan.Term &&
|
|
FirstPmtDate == loan.FirstPmtDate &&
|
|
FinalPmtDate == loan.FinalPmtDate &&
|
|
LoanAmount == loan.LoanAmount &&
|
|
BuyRate == loan.BuyRate &&
|
|
ContractRate == loan.ContractRate &&
|
|
MonthlyPmt == loan.MonthlyPmt &&
|
|
LoanTypeId == loan.LoanTypeId &&
|
|
ApplicationId == loan.ApplicationId &&
|
|
Warranty == loan.Warranty &&
|
|
Gap == loan.Gap &&
|
|
Mbp == loan.Mbp &&
|
|
CreditLife == loan.CreditLife &&
|
|
CreditDisability == loan.CreditDisability &&
|
|
ActionRequired == loan.ActionRequired;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
HashCode hash = new HashCode();
|
|
hash.Add(MemberNumber);
|
|
hash.Add(LoanNumber);
|
|
hash.Add(MemberLastName);
|
|
hash.Add(MemberFirstName);
|
|
hash.Add(MemberInitial);
|
|
hash.Add(DealerOrganizationNumber);
|
|
hash.Add(LoanDate);
|
|
hash.Add(PostedDate);
|
|
hash.Add(FirstPmtDate);
|
|
hash.Add(FinalPmtDate);
|
|
hash.Add(LoanAmount);
|
|
hash.Add(BuyRate);
|
|
hash.Add(ContractRate);
|
|
hash.Add(MonthlyPmt);
|
|
hash.Add(LoanTypeId);
|
|
hash.Add(ApplicationId);
|
|
hash.Add(Warranty);
|
|
hash.Add(Gap);
|
|
hash.Add(Mbp);
|
|
hash.Add(CreditLife);
|
|
hash.Add(CreditDisability);
|
|
hash.Add(ActionRequired);
|
|
return hash.ToHashCode();
|
|
}
|
|
}
|
|
public class LoanValidator : AbstractValidator<Loan>
|
|
{
|
|
public LoanValidator()
|
|
{
|
|
|
|
RuleFor(m => m.LoanTypeId).NotEmpty().WithMessage("Loan type cannot be empty!");
|
|
RuleFor(m => m.DealerOrganizationNumber).NotEmpty().WithMessage("Dealer Organization Number cannot be empty!");
|
|
When(m => m.Dealer != null && string.IsNullOrEmpty(m.Dealer.DealerCode), () =>
|
|
{
|
|
RuleFor(m => m.Dealer.DealerCode).NotEmpty().WithMessage("Dealer Code cannot be empty!");
|
|
|
|
});
|
|
|
|
When(m => m.Dealer != null && string.IsNullOrEmpty(m.Dealer.DealerAccountNumber), () =>
|
|
{
|
|
RuleFor(m => m.Dealer.DealerAccountNumber).NotEmpty().WithMessage("Dealer Account Number cannot be empty!");
|
|
});
|
|
|
|
When(m => m.Dealer != null && string.IsNullOrEmpty(m.Dealer.Name), () =>
|
|
{
|
|
RuleFor(m => m.Dealer.Name).NotEmpty().WithMessage("Dealer Name cannot be empty!");
|
|
});
|
|
|
|
When(m => m.Vehicle != null && string.IsNullOrEmpty(m.Vehicle.VINNumber), () =>
|
|
{
|
|
RuleFor(m => m.Vehicle.VINNumber).NotEmpty().WithMessage("VIN cannot be empty!");
|
|
});
|
|
|
|
RuleFor(m => m.LoanDate).LessThanOrEqualTo(m => m.FirstPmtDate).WithMessage("First Payment Date cannot be before Loan Date!");
|
|
}
|
|
}
|
|
}
|
|
|