Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #88 from AppliedIS/feature-validation2
Browse files Browse the repository at this point in the history
tighter validation and model updates
  • Loading branch information
MrMatt57 committed Nov 1, 2016
2 parents f22e2b9 + 7250dda commit 6edba28
Show file tree
Hide file tree
Showing 22 changed files with 387 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,21 @@ public class ApplicationSubmissionValidator : BaseValidator<ApplicationSubmissio
public ApplicationSubmissionValidator(IEmployerValidator employerValidator, IHourlyWageInfoValidator hourlyWageInfoValidator, IPieceRateWageInfoValidator pieceRateWageInfoValidator, IWorkSiteValidator workSiteValidator, IWIOAValidator wioaValidator)
{
// required
RuleFor(a => a.RepresentativePayeeSocialSecurityBenefits).NotNull();
RuleFor(a => a.ProvidingFacilities).NotNull();
RuleFor(a => a.ReviewedDocumentation).NotNull();
RuleFor(a => a.EIN).NotEmpty();
RuleFor(a => a.ApplicationTypeId).NotNull();
RuleFor(a => a.ApplicationTypeId).NotNull().GreaterThanOrEqualTo(1).LessThanOrEqualTo(2);
RuleFor(a => a.HasPreviousApplication).NotNull();
RuleFor(a => a.HasPreviousCertificate).NotNull();
RuleFor(a => a.EstablishmentType).NotNull().Must(et => et.Any());
RuleFor(a => a.EstablishmentType).NotNull().Must(et => et.Any() && !et.Any(x => x.EstablishmentTypeId < 3) && !et.Any(x => x.EstablishmentTypeId > 6));
RuleFor(a => a.ContactName).NotEmpty();
RuleFor(a => a.ContactPhone).NotEmpty();
RuleFor(a => a.ContactEmail).NotEmpty();
RuleFor(a => a.PayTypeId).NotEmpty();
RuleFor(a => a.PayTypeId).NotEmpty().GreaterThanOrEqualTo(21).LessThanOrEqualTo(23);
RuleFor(a => a.TotalNumWorkSites).NotNull();
RuleFor(a => a.Employer).NotNull().SetValidator(employerValidator);
RuleFor(a => a.WorkSites).NotNull().Must(w => w.Any()).SetCollectionValidator(workSiteValidator);
RuleFor(a => a.WIOA).NotNull().SetValidator(wioaValidator);

// conditional required
RuleFor(a => a.NumEmployeesRepresentativePayee)
.NotEmpty()
.When(a => a.RepresentativePayeeSocialSecurityBenefits.GetValueOrDefault());

When(a => a.ProvidingFacilities.GetValueOrDefault(), () =>
{
RuleFor(a => a.ProvidingFacilitiesDeductionType)
.NotNull()
.Must(p => p.Any());
RuleFor(a => a.ProvidingFacilitiesDeductionTypeOther)
.NotEmpty()
.When(a => a.ProvidingFacilitiesDeductionType != null && a.ProvidingFacilitiesDeductionType.Any(x => x.ProvidingFacilitiesDeductionTypeId == 20));
});

RuleFor(a => a.CertificateNumber)
.NotEmpty()
.When(a => a.HasPreviousCertificate.GetValueOrDefault());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class EmployeeValidator : BaseValidator<Employee>, IEmployeeValidator
public EmployeeValidator()
{
RuleFor(e => e.Name).NotEmpty();
RuleFor(e => e.PrimaryDisabilityId).NotNull();
RuleFor(e => e.PrimaryDisabilityId).NotNull().GreaterThanOrEqualTo(31).LessThanOrEqualTo(38);
RuleFor(e => e.WorkType).NotEmpty();
RuleFor(e => e.NumJobs).NotNull();
RuleFor(e => e.AvgWeeklyHours).NotNull();
Expand Down
22 changes: 14 additions & 8 deletions DOL.WHD.Section14c.Business/Validators/EmployerValidator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DOL.WHD.Section14c.Domain.Models.Submission;
using System.Linq;
using DOL.WHD.Section14c.Domain.Models.Submission;
using FluentValidation;

namespace DOL.WHD.Section14c.Business.Validators
Expand All @@ -14,19 +15,27 @@ public EmployerValidator(IAddressValidator addressValidator, IWorkerCountInfoVal
RuleFor(e => e.PhysicalAddress).NotNull().SetValidator(addressValidator);
RuleFor(e => e.HasDifferentMailingAddress).NotNull();
RuleFor(e => e.HasParentOrg).NotNull();
RuleFor(e => e.EmployerStatusId).NotNull();
RuleFor(e => e.EmployerStatusId).NotNull().GreaterThanOrEqualTo(7).LessThanOrEqualTo(10);
RuleFor(e => e.IsEducationalAgency).NotNull();
RuleFor(e => e.FiscalQuarterEndDate).NotEmpty();
RuleFor(e => e.NumSubminimalWageWorkers).NotNull().SetValidator(workerCountInfoValidator);
RuleFor(e => e.PCA).NotNull();
RuleFor(e => e.SCAId).NotNull();
RuleFor(e => e.EO13658Id).NotNull();
RuleFor(e => e.SCAId).NotNull().GreaterThanOrEqualTo(11).LessThanOrEqualTo(13);
RuleFor(e => e.EO13658Id).NotNull().GreaterThanOrEqualTo(14).LessThanOrEqualTo(16);
RuleFor(e => e.RepresentativePayee).NotNull();
RuleFor(e => e.TakeCreditForCosts).NotNull();
RuleFor(e => e.ProvidingFacilitiesDeductionTypeId).NotNull();
RuleFor(e => e.TemporaryAuthority).NotNull();

// conditional required
When(a => a.TakeCreditForCosts.GetValueOrDefault(), () =>
{
RuleFor(a => a.ProvidingFacilitiesDeductionType)
.NotNull()
.Must(p => p.Any() && !p.Any(x => x.ProvidingFacilitiesDeductionTypeId < 17) && !p.Any(x => x.ProvidingFacilitiesDeductionTypeId > 20));
RuleFor(a => a.ProvidingFacilitiesDeductionTypeOther)
.NotEmpty()
.When(a => a.ProvidingFacilitiesDeductionType != null && a.ProvidingFacilitiesDeductionType.Any(x => x.ProvidingFacilitiesDeductionTypeId == 20));
});
RuleFor(e => e.TradeName).NotEmpty().When(e => e.HasTradeName.GetValueOrDefault());
RuleFor(e => e.PriorLegalName).NotEmpty().When(e => e.LegalNameHasChanged.GetValueOrDefault());
When(e => e.HasParentOrg.GetValueOrDefault(), () =>
Expand All @@ -37,9 +46,6 @@ public EmployerValidator(IAddressValidator addressValidator, IWorkerCountInfoVal
RuleFor(e => e.SendMailToParent).NotNull();
});
RuleFor(e => e.EmployerStatusOther).NotEmpty().When(e => e.EmployerStatusId == 10);
RuleFor(e => e.ProvidingFacilitiesDeductionTypeOther)
.NotEmpty()
.When(e => e.ProvidingFacilitiesDeductionTypeId == 20);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class WIOAWorkerValidator : BaseValidator<WIOAWorker>, IWIOAWorkerValidat
public WIOAWorkerValidator()
{
RuleFor(w => w.FullName).NotEmpty();
RuleFor(w => w.WIOAWorkerVerifiedId).NotNull();
RuleFor(w => w.WIOAWorkerVerifiedId).NotNull().GreaterThanOrEqualTo(39).LessThanOrEqualTo(41);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public WageTypeInfoValidator(IPrevailingWageSurveyInfoValidator prevailingWageSu
RuleFor(w => w.NumWorkers).NotNull();
RuleFor(w => w.JobName).NotEmpty();
RuleFor(w => w.JobDescription).NotEmpty();
RuleFor(w => w.PrevailingWageMethodId).NotNull();
RuleFor(w => w.PrevailingWageMethodId).NotNull().GreaterThanOrEqualTo(24).LessThanOrEqualTo(26);
RuleFor(w => w.AttachmentId).NotNull();

// conditional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class WorkSiteValidator : BaseValidator<WorkSite>, IWorkSiteValidator
{
public WorkSiteValidator(IAddressValidator addressValidator, IEmployeeValidator employeeValidator)
{
RuleFor(w => w.WorkSiteType).NotNull().Must(wst => wst.Any());
RuleFor(w => w.WorkSiteType).NotNull().Must(wst => wst.Any() && !wst.Any(x => x.WorkSiteTypeId < 27) && !wst.Any(x => x.WorkSiteTypeId > 30));
RuleFor(w => w.Name).NotEmpty();
RuleFor(w => w.Address).NotNull().SetValidator(addressValidator);
RuleFor(w => w.SCA).NotNull();
Expand Down
10 changes: 3 additions & 7 deletions DOL.WHD.Section14c.DataAccess/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Entity<AlternateWageData>().Property(a => a.PrevailingWageProvidedBySource).IsRequired();
modelBuilder.Entity<AlternateWageData>().Property(a => a.DataRetrieved).IsRequired();
// ApplicationSubmission
modelBuilder.Entity<ApplicationSubmission>().Property(a => a.RepresentativePayeeSocialSecurityBenefits).IsRequired();
modelBuilder.Entity<ApplicationSubmission>().Property(a => a.ProvidingFacilities).IsRequired();
modelBuilder.Entity<ApplicationSubmission>().Property(a => a.ReviewedDocumentation).IsRequired();
modelBuilder.Entity<ApplicationSubmission>().Property(a => a.EIN).IsRequired();
modelBuilder.Entity<ApplicationSubmission>().Property(a => a.ApplicationTypeId).IsRequired();
modelBuilder.Entity<ApplicationSubmission>().Property(a => a.HasPreviousApplication).IsRequired();
Expand Down Expand Up @@ -86,7 +83,6 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Entity<EmployerInfo>().Property(a => a.EO13658Id).IsRequired();
modelBuilder.Entity<EmployerInfo>().Property(a => a.RepresentativePayee).IsRequired();
modelBuilder.Entity<EmployerInfo>().Property(a => a.TakeCreditForCosts).IsRequired();
modelBuilder.Entity<EmployerInfo>().Property(a => a.ProvidingFacilitiesDeductionTypeId).IsRequired();
modelBuilder.Entity<EmployerInfo>().Property(a => a.TemporaryAuthority).IsRequired();
modelBuilder.Entity<EmployerInfo>().HasRequired(a => a.PhysicalAddress);
modelBuilder.Entity<EmployerInfo>().HasRequired(a => a.NumSubminimalWageWorkers);
Expand Down Expand Up @@ -147,9 +143,9 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
.ToTable("AppSubmissionEstablishmentType")
.HasKey(k => new {k.ApplicationSubmissionId, k.EstablishmentTypeId});

modelBuilder.Entity<ApplicationSubmissionProvidingFacilitiesDeductionType>()
.ToTable("AppSubmissionFacilitiesDeductionType")
.HasKey(k => new { k.ApplicationSubmissionId, k.ProvidingFacilitiesDeductionTypeId });
modelBuilder.Entity<EmployerInfoProvidingFacilitiesDeductionType>()
.ToTable("EmployerInfoFacilitiesDeductionType")
.HasKey(k => new { k.EmployerInfoId, k.ProvidingFacilitiesDeductionTypeId });

modelBuilder.Entity<WorkSiteWorkSiteType>()
.ToTable("WorkSiteWorkSiteType")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
<Compile Include="Migrations\201610301837290_TableKeyUpdates.Designer.cs">
<DependentUpon>201610301837290_TableKeyUpdates.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201611011606064_MoveProvidingFacilitiesField.cs" />
<Compile Include="Migrations\201611011606064_MoveProvidingFacilitiesField.Designer.cs">
<DependentUpon>201611011606064_MoveProvidingFacilitiesField.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repositories\ApplicationRepository.cs" />
Expand Down Expand Up @@ -281,6 +285,9 @@
<EmbeddedResource Include="Migrations\201610301837290_TableKeyUpdates.resx">
<DependentUpon>201610301837290_TableKeyUpdates.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\201611011606064_MoveProvidingFacilitiesField.resx">
<DependentUpon>201611011606064_MoveProvidingFacilitiesField.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace DOL.WHD.Section14c.DataAccess.Migrations
{
using System;
using System.Data.Entity.Migrations;

public partial class MoveProvidingFacilitiesField : DbMigration
{
public override void Up()
{
DropForeignKey("dbo.AppSubmissionFacilitiesDeductionType", "ApplicationSubmissionId", "dbo.ApplicationSubmissions");
DropForeignKey("dbo.AppSubmissionFacilitiesDeductionType", "ProvidingFacilitiesDeductionTypeId", "dbo.Responses");
DropForeignKey("dbo.EmployerInfoes", "ProvidingFacilitiesDeductionTypeId", "dbo.Responses");
DropIndex("dbo.EmployerInfoes", new[] { "ProvidingFacilitiesDeductionTypeId" });
DropIndex("dbo.AppSubmissionFacilitiesDeductionType", new[] { "ApplicationSubmissionId" });
DropIndex("dbo.AppSubmissionFacilitiesDeductionType", new[] { "ProvidingFacilitiesDeductionTypeId" });
CreateTable(
"dbo.EmployerInfoFacilitiesDeductionType",
c => new
{
EmployerInfoId = c.Guid(nullable: false),
ProvidingFacilitiesDeductionTypeId = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.EmployerInfoId, t.ProvidingFacilitiesDeductionTypeId })
.ForeignKey("dbo.Responses", t => t.ProvidingFacilitiesDeductionTypeId, cascadeDelete: true)
.ForeignKey("dbo.EmployerInfoes", t => t.EmployerInfoId, cascadeDelete: true)
.Index(t => t.EmployerInfoId)
.Index(t => t.ProvidingFacilitiesDeductionTypeId);

DropColumn("dbo.ApplicationSubmissions", "RepresentativePayeeSocialSecurityBenefits");
DropColumn("dbo.ApplicationSubmissions", "NumEmployeesRepresentativePayee");
DropColumn("dbo.ApplicationSubmissions", "ProvidingFacilities");
DropColumn("dbo.ApplicationSubmissions", "ProvidingFacilitiesDeductionTypeOther");
DropColumn("dbo.ApplicationSubmissions", "ReviewedDocumentation");
DropColumn("dbo.EmployerInfoes", "ProvidingFacilitiesDeductionTypeId");
DropTable("dbo.AppSubmissionFacilitiesDeductionType");
}

public override void Down()
{
CreateTable(
"dbo.AppSubmissionFacilitiesDeductionType",
c => new
{
ApplicationSubmissionId = c.Guid(nullable: false),
ProvidingFacilitiesDeductionTypeId = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.ApplicationSubmissionId, t.ProvidingFacilitiesDeductionTypeId });

AddColumn("dbo.EmployerInfoes", "ProvidingFacilitiesDeductionTypeId", c => c.Int(nullable: false));
AddColumn("dbo.ApplicationSubmissions", "ReviewedDocumentation", c => c.Boolean(nullable: false));
AddColumn("dbo.ApplicationSubmissions", "ProvidingFacilitiesDeductionTypeOther", c => c.String());
AddColumn("dbo.ApplicationSubmissions", "ProvidingFacilities", c => c.Boolean(nullable: false));
AddColumn("dbo.ApplicationSubmissions", "NumEmployeesRepresentativePayee", c => c.Int());
AddColumn("dbo.ApplicationSubmissions", "RepresentativePayeeSocialSecurityBenefits", c => c.Boolean(nullable: false));
DropForeignKey("dbo.EmployerInfoFacilitiesDeductionType", "EmployerInfoId", "dbo.EmployerInfoes");
DropForeignKey("dbo.EmployerInfoFacilitiesDeductionType", "ProvidingFacilitiesDeductionTypeId", "dbo.Responses");
DropIndex("dbo.EmployerInfoFacilitiesDeductionType", new[] { "ProvidingFacilitiesDeductionTypeId" });
DropIndex("dbo.EmployerInfoFacilitiesDeductionType", new[] { "EmployerInfoId" });
DropTable("dbo.EmployerInfoFacilitiesDeductionType");
CreateIndex("dbo.AppSubmissionFacilitiesDeductionType", "ProvidingFacilitiesDeductionTypeId");
CreateIndex("dbo.AppSubmissionFacilitiesDeductionType", "ApplicationSubmissionId");
CreateIndex("dbo.EmployerInfoes", "ProvidingFacilitiesDeductionTypeId");
AddForeignKey("dbo.EmployerInfoes", "ProvidingFacilitiesDeductionTypeId", "dbo.Responses", "Id", cascadeDelete: true);
AddForeignKey("dbo.AppSubmissionFacilitiesDeductionType", "ProvidingFacilitiesDeductionTypeId", "dbo.Responses", "Id", cascadeDelete: true);
AddForeignKey("dbo.AppSubmissionFacilitiesDeductionType", "ApplicationSubmissionId", "dbo.ApplicationSubmissions", "Id", cascadeDelete: true);
}
}
}
Loading

0 comments on commit 6edba28

Please sign in to comment.