I'm trying to hook up some server side validation so there is some sort of last line of defense so bad data doesn't get through. One of my fields depends on a boolean value. If the boolean is true then the int value must be 0. If it is false then it has to between 1 and 7. This is what I have so far but it's not working.
[ValidApplicationPrimary(ComplianceProfile= NFlagComplianceProfile)]
[Column("APPLICATION_PRIMARY")]
public int ApplicationPrimary { get; set; }
[Required]
[Column("NFLAG_COMPLIANCE_PROFILE")]
public bool NFlagComplianceProfile { get; set; }
public class ValidApplicationPrimary : ValidationAttribute
{
public Boolean ComplianceProfile { get; set; }
public override bool IsValid(object value)
{
if (ComplianceProfile)//If they have a compliance profile the value of Application Primary should be 0
{
if (((Int32)value) == 0)
{
return true;
}
else
{
return false;
}
}
else if (((Int32)value) > 0 && ((Int32)value)<=7) //If Application primary is between 1 and 7 then it is true
{
return true;
}
else //Outside that range its false
return false;
}
I keep getting this error
Error 3 An object reference is required for the non-static field, method, or property 'EntityFrameworkTable.NFlagComplianceProfile.get'