@@ -20,7 +20,7 @@ public EfCoreOrganizationUnitRepository(
20
20
{
21
21
}
22
22
23
- public async Task < List < OrganizationUnit > > GetChildrenAsync (
23
+ public virtual async Task < List < OrganizationUnit > > GetChildrenAsync (
24
24
Guid ? parentId ,
25
25
bool includeDetails = false ,
26
26
CancellationToken cancellationToken = default )
@@ -31,7 +31,7 @@ public async Task<List<OrganizationUnit>> GetChildrenAsync(
31
31
. ToListAsync ( GetCancellationToken ( cancellationToken ) ) ;
32
32
}
33
33
34
- public async Task < List < OrganizationUnit > > GetAllChildrenWithParentCodeAsync (
34
+ public virtual async Task < List < OrganizationUnit > > GetAllChildrenWithParentCodeAsync (
35
35
string code ,
36
36
Guid ? parentId ,
37
37
bool includeDetails = false ,
@@ -43,7 +43,7 @@ public async Task<List<OrganizationUnit>> GetAllChildrenWithParentCodeAsync(
43
43
. ToListAsync ( GetCancellationToken ( cancellationToken ) ) ;
44
44
}
45
45
46
- public async Task < List < OrganizationUnit > > GetListAsync (
46
+ public virtual async Task < List < OrganizationUnit > > GetListAsync (
47
47
string sorting = null ,
48
48
int maxResultCount = int . MaxValue ,
49
49
int skipCount = 0 ,
@@ -56,7 +56,7 @@ public async Task<List<OrganizationUnit>> GetListAsync(
56
56
. PageBy ( skipCount , maxResultCount )
57
57
. ToListAsync ( GetCancellationToken ( cancellationToken ) ) ;
58
58
}
59
- public async Task < List < OrganizationUnit > > GetListAsync (
59
+ public virtual async Task < List < OrganizationUnit > > GetListAsync (
60
60
IEnumerable < Guid > ids ,
61
61
bool includeDetails = false ,
62
62
CancellationToken cancellationToken = default )
@@ -67,7 +67,7 @@ public async Task<List<OrganizationUnit>> GetListAsync(
67
67
. ToListAsync ( GetCancellationToken ( cancellationToken ) ) ;
68
68
}
69
69
70
- public async Task < OrganizationUnit > GetAsync (
70
+ public virtual async Task < OrganizationUnit > GetAsync (
71
71
string displayName ,
72
72
bool includeDetails = true ,
73
73
CancellationToken cancellationToken = default )
@@ -78,22 +78,65 @@ public async Task<OrganizationUnit> GetAsync(
78
78
ou => ou . DisplayName == displayName ,
79
79
GetCancellationToken ( cancellationToken )
80
80
) ;
81
- }
82
- public async Task < List < IdentityRole > > GetRolesAsync (
83
- Guid organizationUnitId , bool includeDetails = false ,
81
+ }
82
+
83
+ public virtual async Task < List < IdentityRole > > GetRolesAsync (
84
+ OrganizationUnit organizationUnit ,
85
+ bool includeDetails = false ,
84
86
CancellationToken cancellationToken = default )
85
87
{
86
88
var query = from organizationRole in DbContext . Set < OrganizationUnitRole > ( )
87
89
join role in DbContext . Roles . IncludeDetails ( includeDetails ) on organizationRole . RoleId equals role . Id
88
- where organizationRole . OrganizationUnitId == organizationUnitId
90
+ where organizationRole . OrganizationUnitId == organizationUnit . Id
89
91
select role ;
90
92
91
93
return await query . ToListAsync ( GetCancellationToken ( cancellationToken ) ) ;
92
94
}
93
95
96
+ public virtual async Task < List < IdentityUser > > GetMembersAsync (
97
+ OrganizationUnit organizationUnit ,
98
+ string sorting = null ,
99
+ int maxResultCount = int . MaxValue ,
100
+ int skipCount = 0 ,
101
+ string filter = null ,
102
+ bool includeDetails = false ,
103
+ CancellationToken cancellationToken = default
104
+ )
105
+ {
106
+ var query = from userOu in DbContext . Set < IdentityUserOrganizationUnit > ( )
107
+ join user in DbContext . Users . IncludeDetails ( includeDetails ) on userOu . UserId equals user . Id
108
+ where userOu . OrganizationUnitId == organizationUnit . Id
109
+ select user ;
110
+
111
+ if ( ! filter . IsNullOrWhiteSpace ( ) )
112
+ {
113
+ query = query . Where ( u =>
114
+ u . UserName . Contains ( filter ) ||
115
+ u . Email . Contains ( filter ) ||
116
+ ( u . PhoneNumber != null && u . PhoneNumber . Contains ( filter ) )
117
+ ) ;
118
+ }
119
+
120
+ return await query . OrderBy ( sorting ?? nameof ( IdentityUser . UserName ) )
121
+ . PageBy ( skipCount , maxResultCount )
122
+ . ToListAsync ( GetCancellationToken ( cancellationToken ) ) ;
123
+ }
124
+
125
+ public virtual async Task < int > GetMembersCountAsync (
126
+ OrganizationUnit organizationUnit ,
127
+ CancellationToken cancellationToken = default )
128
+ {
129
+ var query = from userOu in DbContext . Set < IdentityUserOrganizationUnit > ( )
130
+ join user in DbContext . Users on userOu . UserId equals user . Id
131
+ where userOu . OrganizationUnitId == organizationUnit . Id
132
+ select user ;
133
+
134
+ return await query . CountAsync ( GetCancellationToken ( cancellationToken ) ) ;
135
+ }
136
+
94
137
public override IQueryable < OrganizationUnit > WithDetails ( )
95
138
{
96
139
return GetQueryable ( ) . IncludeDetails ( ) ;
97
- }
140
+ }
98
141
}
99
142
}
0 commit comments