28 lines
837 B
C#
28 lines
837 B
C#
using System.Collections.Concurrent;
|
|
|
|
namespace YD_TrainingCompetition_Api.Competition;
|
|
|
|
public sealed class ParticipantDirectory : IParticipantDirectory
|
|
{
|
|
private readonly ConcurrentDictionary<string, RosterEntry> _entries = new(StringComparer.OrdinalIgnoreCase);
|
|
|
|
public void ApplyRoster(IEnumerable<RosterEntry> entries)
|
|
{
|
|
_entries.Clear();
|
|
foreach (var e in entries)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(e.DeviceId))
|
|
{
|
|
_entries[e.DeviceId] = e;
|
|
}
|
|
}
|
|
}
|
|
|
|
public RosterEntry? FindByDeviceId(string deviceId)
|
|
{
|
|
return _entries.TryGetValue(deviceId, out var e) ? e : null;
|
|
}
|
|
|
|
public IReadOnlyCollection<RosterEntry> GetAll() => _entries.Values.OrderBy(x => x.DeviceId, StringComparer.OrdinalIgnoreCase).ToArray();
|
|
}
|