-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathPickUserAutocomplete.razor.cs
More file actions
56 lines (47 loc) · 1.9 KB
/
PickUserAutocomplete.razor.cs
File metadata and controls
56 lines (47 loc) · 1.9 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
using CleanArchitecture.Blazor.Application.Features.Identity.DTOs;
namespace CleanArchitecture.Blazor.Server.UI.Components.Autocompletes;
public class PickUserAutocomplete<T> : MudAutocomplete<ApplicationUserDto>
{
public PickUserAutocomplete()
{
SearchFunc = SearchKeyValues;
ToStringFunc = dto => dto?.UserName;
Clearable = true;
Dense = true;
ResetValueOnEmptyText = true;
ShowProgressIndicator = true;
MaxItems = 50;
}
[Parameter] public string? TenantId { get; set; }
[Inject] private IDataSourceService<ApplicationUserDto> UserService { get; set; } = default!;
protected override void OnInitialized()
{
UserService.OnChange += TenantsService_OnChange;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await UserService.InitializeAsync();
}
}
private async Task TenantsService_OnChange()
{
await InvokeAsync(StateHasChanged);
}
protected override async ValueTask DisposeAsyncCore()
{
UserService.OnChange -= TenantsService_OnChange;
await base.DisposeAsyncCore();
}
private Task<IEnumerable<ApplicationUserDto>> SearchKeyValues(string? value, CancellationToken cancellation)
{
var result = UserService.DataSource.Where(x => x.TenantId != null && x.TenantId.Equals(TenantId));
if (!string.IsNullOrEmpty(value))
result = UserService.DataSource.Where(x => x.TenantId != null && x.TenantId.Equals(TenantId) &&
(x.UserName.Contains(value,
StringComparison.OrdinalIgnoreCase) ||
x.Email.Contains(value, StringComparison.OrdinalIgnoreCase)));
return Task.FromResult(result);
}
}