I am developing an Intranet application and have successfully integrated with Active Directory.
When we add a new customer I would like to assign a Customer Advisor from a dropdown list.
I am able to populate the dropdown list using the following
PrincipalContext pc = new PrincipalContext(ContextType.Domain, "DOMAIN", "dc=domain,dc=org");
GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, "customerAdvisors");
ViewBag.Guid = new SelectList(group.Members, "Guid", "DisplayName");
I would like to then store the Guid of the selected user along with the Customer data in the database.
However, I am unsure of how to setup foreign key constraints in my Model as the table I am joining to is within Active Directory.
Do I need to create a separate Employee table within my DB and sync the required fields or is there a simplified way of doing this?
I’ve never done this but some quick research makes it look possible.
You could just save the Guid for your adviser on your Customer. The AD Guid can go into the Guid data type. You should be able to query individual users by using this method:
UserPrincipal user =
UserPrincipal.FindByIdentity(pc, yourUsersGuidAsAString);
The down side is that every time you want your customer adviser’s info (like their name or email address) you will have to do a separate query to AD. Harder to use ORM.
In my application I have a different use case, but I have also integrated my application with AD. The route that I took was to save this information in my own DB instead of hitting AD every time. In large part because my architecture makes it hard to get to AD in the same way you can. Also it’s easier to use ORM (like entity framework in my case) to pull in the information that I want. The downside to this is then you need to ensure that the information you have in your database is reasonably up to date with what’s in AD.
You will have to make the judgement on which approach makes the most sense for your architecture/use case.
Hope that helps.