I need to ckeck if Role is in Roles list collection, if isnt, throw validation result. How can i compare this or how can i solve this other way?
public class UserViewModel:IValidatableObject
{
[Required]
public string Username { get; set; }
public IEnumerable<string> Roles { get; set; }
[Required]
public string Rola { get; set; }
public UserViewModel()
{
Repozytorium db = new Repozytorium();
Roles = db.GetAllRoles();
}
public UserViewModel(string userName, string rola)
{
Repozytorium db = new Repozytorium();
Roles = db.GetAllRoles();
Username = userName;
Rola = rola;
}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if(Roles != Roles ) //this dont work
yield return new ValidationResult("role isnt valid", new string[] { "Rola" });
}
}