@if (Title != null)
{
@Title
}
@if (ShowFullName)
{
@student.FirstNameLastName
}
else
{
@student.FirstName
}
@if (ShowGrade)
{
- Grade @student.Grade
}
@if (SelectedStudents.Any())
{
@foreach (var student in SelectedStudents.OrderBy(s => s.FirstName))
{
}
}
@code {
[Parameter]
public IEnumerable Students { get; set; } = [];
[Parameter]
public IEnumerable SelectedStudents { get; set; } = [];
[Parameter]
public EventCallback> SelectedStudentsChanged { get; set; }
[Parameter]
public string? Title { get; set; }
[Parameter]
public string Label { get; set; } = "Search Students";
[Parameter]
public bool ShowFullName { get; set; } = true;
[Parameter]
public bool ShowGrade { get; set; } = false;
private Student? _currentStudent
{
get => _currentStudentValue;
set
{
_currentStudentValue = value;
if (value != null && !SelectedStudents.Contains(value))
{
var updatedList = SelectedStudents.Append(value).ToList();
SelectedStudentsChanged.InvokeAsync(updatedList);
_currentStudentValue = null;
}
}
}
private Student? _currentStudentValue;
private MudAutocomplete? _autocomplete;
private async Task> SearchStudents(string? searchText, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(searchText))
return Students.Where(s => !SelectedStudents.Contains(s));
var search = searchText.ToLower();
return Students
.Where(s => !SelectedStudents.Contains(s))
.Where(s => s.FirstName.ToLower().Contains(search) ||
s.LastName.ToLower().Contains(search))
.OrderBy(s => s.FirstName);
}
private void RemoveStudent(Student student)
{
var updatedList = SelectedStudents.Where(s => s.Id != student.Id).ToList();
SelectedStudentsChanged.InvokeAsync(updatedList);
}
}