public async Task <Participant <Player> > AddPlayerToTournamentAsync(string tournamentId, Participant <Player> player) { var playerRef = new TournamentPlayer() { Player = new SanityReference <Player>() { Ref = player.Item.Id, SanityKey = player.Item.Id, }, Information = player.Information.ToList(), ToornamentId = player.ToornamentId, }; SanityTournament tournament = await Sanity.DocumentSet <SanityTournament>().GetAsync(tournamentId); if (tournament == null || tournament.SignupType == "team" || !tournament.RegistrationOpen) { return(null); } if (tournament.SoloPlayers == null) { tournament.SoloPlayers = new List <TournamentPlayer>(); } if (tournament.SoloPlayers.Find(t => t.Player.Ref == player.Item.Id) != null) { return(null); } tournament.SoloPlayers.Add(playerRef); await Sanity.DocumentSet <SanityTournament>().Update(tournament).CommitAsync(); return(player); }
// class ParticipantResult<T> { // public Participant<T>[] items { get; set; } // } public Task <TournamentAdminInfo> GetAdminInfoAsync(User requester, string tournamentId) { var lang = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; return(Cache.GetOrCreateAsync <TournamentAdminInfo>($"Sanity_Tournament_{tournamentId}_Admin_{lang}", async(c) => { c.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(20); SanityTournament tournament = await Sanity.DocumentSet <SanityTournament>().Where(t => t.Id == tournamentId && t.Responsible.Ref == requester.Id)?.FirstOrDefaultAsync(); if (tournament != null) { return tournament.ToTournamentAdminInfo(Sanity.HtmlBuilder); } return new TournamentAdminInfo(); })); }
public async Task <Participant <Team> > AddTeamToTournamentAsync(string tournamentId, Participant <Team> team) { var teamRef = new TournamentTeam() { Team = new SanityReference <SanityTeam>() { Ref = team.Item.Id, }, Information = team.Information.ToList(), ToornamentId = team.ToornamentId, }; SanityTournament tournament = await Sanity.DocumentSet <SanityTournament>().GetAsync(tournamentId); if (tournament == null || tournament.TeamSize.Min > team.Item.Players.Count + 1 || tournament.TeamSize.Max < team.Item.Players.Count + 1 || tournament.SignupType == "solo" || !tournament.RegistrationOpen) { return(null); } if (!string.IsNullOrEmpty(tournament.Id)) { if (tournament.Teams == null) { tournament.Teams = new List <TournamentTeam>(); } if (tournament.Teams.Find(t => t.Team.Ref == team.Item.Id) == null) { tournament.Teams.Add(teamRef); await Sanity.DocumentSet <SanityTournament>().Update(tournament).CommitAsync(); return(team); } } return(null); }