I have a model like this with a couple of fields such as name, email and phone.
All of these are set with the [Required] attribute.
What I would like to do is override the RequiredAttribute and only require the property if the current visitor of the website is not an administrator. So basically an administrator can type what they like or leave a field empty where as normal users cannot.
Can anyone point me in the right direction or advise on the best way to acheive this ?
To find out if a visitor is admin I use:
var permissionId = Helpers.ConvertToInt(Services.UserService.GetCurrentPermissionId().ToString());
If this is 0 or 1 then the visitor is not an administrator so the field should be required.
I would suggest looking into using FluentValidation which will allow you to specify much more complicated rules then the built in data annotations allow without having to build custom attributes.
You could then solve this by using syntax similar to this: