I have a table containing AD users info inside my database. Some of the table properties will be updated using Sync job (such as first name, last name, email address,, etc), while other will be added by users inside my system such as Primary Role, Secondary role, OverAll Performance, etc.
I have set these values as Required inside my model class, while they allow nulls inside the DB:-
public class SyncADUsers
{
[Required]
[StringLength(200)]
public string PrimaryRole { get; set; }
[StringLength(250)]
public string SecondaryRole { get; set; }
[Required]
public int OverAllPerfomance { get; set; }
[Required]
[StringLength(50)]
public string FirstName { get; set; }
[Required]
[StringLength(50)]
public string LastName { get; set; }
}
But the problem is that when the Sync job start it will raise a validation error that Primary Role, Secondary role, OverAllPerformance are required for any new user that is added to the AD and not yet added to my system. But I need these field to be required only when users try to update the users info inside my system , but to by pass this validation when the sync job start working (especially on new users that are added to the AD , and not yet added to my system database..) Can anyone advice on this? Thanks