I have a UserGroup table which stores the GroupID and the associated UserName. Currently the users exists inside the active directory, so i do not have a Users table. But before assigning any user to the UserGroup table i want to check if the user already defined inside Active Directory or not. so i find writing a validation object inside my UserGroup Model object a good approach so i wrote the following insdie my USerGroup Partial class :-
List<DomainContext> results = new List<DomainContext>();
using (var context = new PrincipalContext(ContextType.Domain, "WIN-SPDEV"))
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
var searchResults = searcher.FindAll();
foreach (Principal p in searchResults)
{
//not sure what to write here !!!
}}
yield return new ValidationResult("UserName does not exsists.");}
But i am not sure how i can implement the uniqueness checking !!!