368d6fafea
Code backup
52 lines
2.0 KiB
C#
52 lines
2.0 KiB
C#
using DevExtreme.AspNet.Data;
|
|
using DevExtreme.AspNet.Mvc;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Localization;
|
|
using System.Collections.Generic;
|
|
using System.DirectoryServices;
|
|
using System.DirectoryServices.AccountManagement;
|
|
using System.Threading.Tasks;
|
|
using webapp_local.Models;
|
|
using webapp_shared;
|
|
using webapp_shared.Code;
|
|
|
|
namespace webapp_local.Pages.IT
|
|
{
|
|
[UserPermissionsOneOfThesePolicies("CanViewUserList")]
|
|
[BindProperties]
|
|
public class UserListModel : _LayoutModel
|
|
{
|
|
public UserListModel(IStringLocalizer<_LayoutModel> _localizer, IConfiguration _config, UserManager<ApplicationUser> _userManager) : base(_localizer, _config, _userManager)
|
|
{
|
|
}
|
|
|
|
public async Task<JsonResult> OnGetADUserData(DataSourceLoadOptions options)
|
|
{
|
|
var ret = new List<ArrayADUser>();
|
|
int index = 0;
|
|
|
|
using (var context = new PrincipalContext(ContextType.Domain, "pal.local"))
|
|
{
|
|
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
|
|
{
|
|
foreach (var result in searcher.FindAll())
|
|
{
|
|
DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
|
|
|
|
ret.Add(new ArrayADUser()
|
|
{
|
|
id = index++,
|
|
Initials = de.Properties.Contains("Initials") ? de.Properties["Initials"].Value.ToString() : "",
|
|
SamAccountName = de.Properties.Contains("SamAccountName") ? de.Properties["SamAccountName"].Value.ToString() : "",
|
|
Name = de.Properties.Contains("Name") ? de.Properties["Name"].Value.ToString() : "",
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return new JsonResult(DataSourceLoader.Load(ret, options));
|
|
}
|
|
}
|
|
}
|