请告诉我如何检查用户是否填写了组织字段
我正在 MVC 5 上制作电话簿。有一个模型和一个控制器。
型号
public class Person
{
public string DisplayName { get; set; }
public string Office { get; set; }
public string PhoneNumber { get; set; }
public string ExtensionPhoneNumber { get; set; }
public string Email { get; set; }
public string Department { get; set; }
//public string Title { get; set; }
public int DepartmentNumber { get; set; }
public string Subdivision { get; set; }
public string Manager { get; set; }
public string Mobile { get; set; }
public int EmployeeNumber { get; set; }
}
控制器
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
public class PeopleController : Controller
{
public ActionResult Home(string department)
{
IEnumerable<Person> persons = GetPeople();
return View(persons);
}
public static List<Person> GetPeople()
{
List<Person> people = new List<Person>();
var path = new PrincipalContext(ContextType.Domain, "RCSON.local", "OU=RCSON, DC=RCSON, DC=local");
UserPrincipal user = new UserPrincipal(path);
user.Enabled = true;
//user.Name = "*";
//user.VoiceTelephoneNumber = "*";
//user.EmailAddress = "*";
//user.Description = "";
var search = new System.DirectoryServices.AccountManagement.PrincipalSearcher();
search.QueryFilter = user;
var results = search.FindAll();
foreach (UserPrincipal item in results)
{
var directoryEntry = item.GetUnderlyingObject() as DirectoryEntry;
people.Add(new Person
{
DisplayName = item.Name,
PhoneNumber = item.VoiceTelephoneNumber,
ExtensionPhoneNumber = item.VoiceTelephoneNumber,
Email = item.EmailAddress,
Office = directoryEntry.Properties["physicalDeliveryOfficeName"].Value as string,
Department = directoryEntry.Properties["subdivision"].Value as string,
//Title = directoryEntry.Properties["title"].Value as string,
DepartmentNumber = Convert.ToInt32(directoryEntry.Properties["departmentNumber"].Value),
Subdivision = directoryEntry.Properties["department"].Value as string,
Manager = directoryEntry.Properties["manager"].Value as string,
Mobile = directoryEntry.Properties["mobile"].Value as string,
EmployeeNumber = Convert.ToInt32(directoryEntry.Properties["employeeNumber"].Value)
});
}
return people;
}
}
[在此处输入图片描述][1] [1]:https://i.stack.imgur.com/kv2vh.jpg
如何过滤具有组织名称的用户。