示例#1
0
    private string GetAccountFromAD(string familyName, string firstName, string middleName, string email)
    {
        var adEmployees = ActiveDirectoryHelper.GetEmployeesFromAd();

        if (adEmployees == null)
        {
            //return string.Empty;
            return(null);
        }

        /*im
         * var foundEmployeeByCredentials =
         * adEmployees.Where(x => (x.ConcatenatedCredentials == familyName.ToLower() + firstName.ToLower())).ToList();
         * if (foundEmployeeByCredentials.Any())
         * {
         * if (foundEmployeeByCredentials.Count == 1)
         * {
         * var account = ACCOUNT_DOMAIN + foundEmployeeByCredentials[0].Account;
         * return account;
         * }
         * else
         * {
         * var accountWithMiddleName = foundEmployeeByCredentials.Where(x => x.MiddleName == middleName).ToList();
         * if (accountWithMiddleName.Any() && accountWithMiddleName.Count() == 1)
         * {
         *  var account = ACCOUNT_DOMAIN + accountWithMiddleName[0].Account;
         *  return account;
         * }
         * }
         * }
         * else
         * {
         * if (email != null)
         * {
         * var foundEmployeeByEmail = adEmployees.FirstOrDefault(x => (x.Email.ToLower() == email.ToLower()));
         * if (foundEmployeeByEmail != null)
         * {
         *  return ACCOUNT_DOMAIN + foundEmployeeByEmail.Account;
         * }
         * }
         *      else
         *      {
         *              return null;
         *      }
         * }
         */

        if (email != null)
        {
            var foundEmployeeByEmail = adEmployees.FirstOrDefault(x => (x.Email.ToLower() == email.ToLower()));
            if (foundEmployeeByEmail != null)
            {
                return(ACCOUNT_DOMAIN + foundEmployeeByEmail.Account);
            }
        }
        //return string.Empty;
        return(null);
    }