@inject KeyService KeyService
@inject IMessageService MessageService
@if (Keys != null)
{
@switch (context.AllocationMethod)
{
case KeyAllocationMethod.MacAddress:
@context.ClaimedByMacAddress
break;
case KeyAllocationMethod.UserAccount:
@context.ClaimedByUser?.UserName
break;
}
@if (context.IsAllocated())
{
}
}
@code {
[Parameter] public Guid GameId { get; set; }
ICollection Keys = new List();
int AllocatedKeys;
bool EditModalVisible = false;
DataTable Table;
StandaloneCodeEditor? Editor;
StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
{
return new StandaloneEditorConstructionOptions
{
AutomaticLayout = true,
Language = "text",
Value = String.Join('\n', Keys.Select(k => k.Value)),
Theme = "vs-dark",
};
}
protected override async Task OnInitializedAsync()
{
if (Keys == null)
Keys = new List();
Keys = await KeyService.GetAsync(k => k.GameId == GameId);
AllocatedKeys = Keys.Count(k => k.IsAllocated());
}
void Edit()
{
EditModalVisible = true;
}
async Task Release(Key key)
{
await KeyService.ReleaseAsync(key);
await MessageService.SuccessAsync("Key was unallocated!");
}
async Task Save()
{
var value = await Editor.GetValue();
var keys = value.Split("\n").Select(k => k.Trim()).Where(k => !String.IsNullOrWhiteSpace(k)).ToList();
var keysDeleted = Keys.Where(k => !keys.Contains(k.Value)).ToList();
var keysAdded = keys.Where(k => !Keys.Any(gk => gk.Value == k)).ToList();
foreach (var key in keysDeleted)
KeyService.DeleteAsync(key);
foreach (var key in keysAdded)
await KeyService.AddAsync(new Key()
{
GameId = GameId,
Value = key
});
EditModalVisible = false;
MessageService.Success("Keys updated!");
}
}