- App Logger entfernt und durch die Implementierung des `ILogger`-Interfaces ersetzt, um eine konsistente Logging-Architektur zu gewährleisten. - API für die Nutzung von NLog konfiguriert, um eine leistungsstarke und flexible Logging-Lösung bereitzustellen. - Konfigurationsdateien und Setup-Anpassungen für die Integration von NLog in die API vorgenommen.
115 lines
4.1 KiB
C#
115 lines
4.1 KiB
C#
using DAL._Shared.SharedModels;
|
|
using HRD.LDAPService;
|
|
using HRD.WebApi.Repositories;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DAL._Shared.SharedRepositories
|
|
{
|
|
public class WebAppEmployeeInfoRepository : BaseRepository<WebAppEmployeeInfo>
|
|
|
|
{
|
|
public WebAppEmployeeInfoRepository(WebApiContext context, ILogger<WebAppEmployeeInfoRepository> logger) : base(context, logger)
|
|
{
|
|
}
|
|
|
|
private IQueryable<WebAppEmployeeInfo> PrepareList(List<int> departmentIds)
|
|
{
|
|
IQueryable<WebAppEmployeeInfo> items = RepositoryContext.Set<WebAppEmployeeInfo>().AsNoTracking();
|
|
return items.Where(x => departmentIds.Contains(x.DepartmentId));
|
|
}
|
|
|
|
public async Task<List<string>> GetEmailListForDepartmentsAsync(List<int> departmentIds)
|
|
{
|
|
return await PrepareList(departmentIds).Select(x => x.Email).ToListAsync();
|
|
}
|
|
|
|
public async Task<List<string>> GetLoginnameListForDepartmentsAsync(List<int> departmentIds)
|
|
{
|
|
return await PrepareList(departmentIds).Select(x => x.LoginName).ToListAsync();
|
|
}
|
|
|
|
public async Task<List<string>> GetShortnameListForDepartmentsAsync(List<int> departmentIds)
|
|
{
|
|
return await PrepareList(departmentIds).Select(x => x.ShortName).ToListAsync();
|
|
}
|
|
|
|
public async Task<string> GetShortnameForLoginAsync(string loginname)
|
|
{
|
|
return (await RepositoryContext.Set<WebAppEmployeeInfo>().FirstAsync(x => x.LoginName == loginname)).ShortName;
|
|
}
|
|
|
|
//----------------
|
|
public List<string> GetEmailListForDepartments(List<int> departmentIds)
|
|
{
|
|
return PrepareList(departmentIds).Select(x => x.Email).ToList();
|
|
}
|
|
|
|
public List<string> GetLoginnameListForDepartments(List<int> departmentIds)
|
|
{
|
|
return PrepareList(departmentIds).Select(x => x.LoginName).ToList();
|
|
}
|
|
|
|
public List<string> GetShortnameListForDepartments(List<int> departmentIds)
|
|
{
|
|
return PrepareList(departmentIds).Select(x => x.ShortName).ToList();
|
|
}
|
|
|
|
public string GetShortnameForLogin(string loginname)
|
|
{
|
|
return RepositoryContext.Set<WebAppEmployeeInfo>().First(x => x.LoginName == loginname).ShortName;
|
|
}
|
|
|
|
//----------------
|
|
public bool PrepareForUserLoginnameOrLoginnameListFilter(LdapUser ldapUser, ref string loginName, ref List<string> loginNameList)
|
|
{
|
|
if (ldapUser.IsAdmin() || ldapUser.IsMaster())
|
|
{
|
|
}
|
|
else if (ldapUser.IsDepartmentMaster() || ldapUser.IsDepartmentUser())
|
|
{
|
|
loginNameList = GetLoginnameListForDepartments(ldapUser.DepartmentIdListAll());
|
|
loginName = default;
|
|
}
|
|
else if (ldapUser.IsUser())
|
|
{
|
|
loginNameList = default;
|
|
loginName = ldapUser.LoginName;
|
|
}
|
|
else
|
|
{
|
|
return false; //shouldn't happen
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool PrepareForUserEmailOrEmailListFilter(LdapUser ldapUser, ref string EmailBV, ref List<string> EmailBVList)
|
|
{
|
|
if (string.IsNullOrEmpty(EmailBV)) //check for user & master
|
|
{
|
|
if (ldapUser.IsAdmin() || ldapUser.IsMaster())
|
|
{
|
|
// No correction
|
|
}
|
|
else if (ldapUser.IsDepartmentMaster() || ldapUser.IsDepartmentUser())
|
|
{
|
|
EmailBVList = GetEmailListForDepartments(ldapUser.DepartmentIdListAll());
|
|
EmailBV = default;
|
|
}
|
|
else if (ldapUser.IsUser())
|
|
{
|
|
EmailBVList = default;
|
|
EmailBV = ldapUser.Email;
|
|
}
|
|
else
|
|
{
|
|
return false; //shouldn't happen
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
} |