-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApplicantProfileAppService.cs
More file actions
69 lines (62 loc) · 2.49 KB
/
ApplicantProfileAppService.cs
File metadata and controls
69 lines (62 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Unity.GrantManager.Applications;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TenantManagement;
namespace Unity.GrantManager.Applicants
{
[RemoteService(false)]
public class ApplicantProfileAppService(ICurrentTenant currentTenant,
ITenantRepository tenantRepository,
IRepository<ApplicationFormSubmission, Guid> applicationFormSubmissionRepository)
: ApplicationService, IApplicantProfileAppService
{
public async Task<ApplicantProfileDto> GetApplicantProfileAsync(ApplicantProfileRequest request)
{
return await Task.FromResult(new ApplicantProfileDto
{
ProfileId = request.ProfileId,
Subject = request.Subject,
Issuer = request.Issuer,
Email = string.Empty,
DisplayName = string.Empty
});
}
public async Task<List<ApplicantTenantDto>> GetApplicantTenantsAsync(ApplicantProfileRequest request)
{
// Extract the username part from the OIDC sub (part before '@')
var subUsername = request.Subject.Contains('@')
? request.Subject[..request.Subject.IndexOf('@')].ToUpper()
: request.Subject.ToUpper();
var result = new List<ApplicantTenantDto>();
// Get all tenants from the host context
using (currentTenant.Change(null))
{
var tenants = await tenantRepository.GetListAsync();
// Query each tenant's database for matching submissions
foreach (var tenant in tenants)
{
using (currentTenant.Change(tenant.Id))
{
var queryable = await applicationFormSubmissionRepository.GetQueryableAsync();
var hasMatchingSubmission = queryable.Any(s => s.OidcSub == subUsername);
if (hasMatchingSubmission)
{
result.Add(new ApplicantTenantDto
{
TenantId = tenant.Id,
TenantName = tenant.Name
});
}
}
}
}
return result;
}
}
}