using System; using System.Collections.Generic; using System.DirectoryServices.AccountManagement; using System.Linq; using System.Web; using Fab2ApprovalSystem.Models; namespace Fab2ApprovalSystem.Utilities { public class UserUtilities { public List GetMesaUsers() { PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "infineon.com", "DC=infineon,DC=com", "MESfisharepoint", "GaN2020=BestWafers!"); GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "MES-IFX-Employees-Mesa"); List MesaUsers = new List(); if (grp != null) { foreach (Principal p in grp.GetMembers(true)) { MesaUsers.Add(new AllUserModel { UserName = p.Name, DisplayName = p.DisplayName } ); //Console.WriteLine(p.Name); } grp.Dispose(); } ctx.Dispose(); MesaUsers = (from a in MesaUsers orderby a.DisplayName ascending select a).ToList(); return MesaUsers; } } }