webemsim/Storage.cs

50 lines
1.2 KiB
C#

namespace WebEMSim
{
public class Storage
{
public static Storage Shared = new Storage();
private Dictionary<string, Tournament> tournamentStore = new Dictionary<string, Tournament>();
public Tournament? CreateTournament()
{
Tournament tournament = new();
string id = tournament.ID;
bool success = tournamentStore.TryAdd(id, tournament);
if (!success) return null;
return tournament;
}
public Tournament? GetTournament(string id)
{
Tournament? tournament = null;
bool success = tournamentStore.TryGetValue(id, out tournament);
if(!success)
return null;
return tournament;
}
public List<string> ListTournaments()
{
return [.. tournamentStore.Keys];
}
public bool? DeleteTournament(string id)
{
Tournament? tournament = null;
bool found = tournamentStore.TryGetValue(id, out tournament);
if (!found)
return null;
return tournamentStore.Remove(id);
}
}
}