public User GetUser(User.Pid pid) { PrincipalContext sContext = new PrincipalContext(ContextType.Domain); _logger.Debug($"Using PrincipalContext: {context.Name} - Server: {context.ConnectedServer}"); _logger.Debug($"Searching by identity of: Pid-{pid}"); UserPrincipal result = UserPrincipal.FindByIdentity(sContext, IdentityType.SamAccountName, pid.Identity); if (!string.IsNullOrWhiteSpace(result.SamAccountName) && !string.IsNullOrWhiteSpace(result.EmailAddress) && (!string.IsNullOrEmpty(result.GivenName) || !string.IsNullOrEmpty(result.Surname))) { User user = new User() { FirstName = result.GivenName, LastName = result.Surname, PayId = new User.Pid(result.SamAccountName), EmailAddress = result.EmailAddress }; _logger.Trace(LoggerHelper.ExecutedFunctionMessage(user, pid)); return(user); } else { StringBuilder stringBuilder = new StringBuilder(); if (!string.IsNullOrWhiteSpace(result.SamAccountName)) { stringBuilder.Append($"SamAccountName value: {result.SamAccountName}, "); } if (!string.IsNullOrWhiteSpace(result.EmailAddress)) { stringBuilder.Append($"EmailAddress value: {result.EmailAddress}, "); } if (!string.IsNullOrEmpty(result.GivenName)) { stringBuilder.Append($"GivenName value: {result.GivenName}, "); } if (!string.IsNullOrEmpty(result.Surname)) { stringBuilder.Append($"Surname value: {result.Surname} "); } _logger.Error($"Value is missing: {stringBuilder.ToString()}"); _logger.Trace(LoggerHelper.ExecutedFunctionMessage(null, pid)); return(null); } }
public User GetUser(User.Pid pid) { PrincipalContext sContext = new PrincipalContext(ContextType.Domain); UserPrincipal result = UserPrincipal.FindByIdentity(sContext, IdentityType.SamAccountName, pid.Identity); if (!string.IsNullOrWhiteSpace(result.SamAccountName) && !string.IsNullOrWhiteSpace(result.EmailAddress) && (!string.IsNullOrEmpty(result.GivenName) || !string.IsNullOrEmpty(result.Surname))) { return(new User() { FirstName = result.GivenName, LastName = result.Surname, PayId = new User.Pid(result.SamAccountName), EmailAddress = result.EmailAddress }); } else { return(null); } }
public User GetUser(User.Pid pid) { return(stubbedUsers.Where(x => x.PayId.Identity == pid.Identity).First()); }