コード例 #1
0
        public async Task <IActionResult> AddTeamToTournamentAsync(string tournamentId, Participant <Team> addTeam)
        {
            if (await Session.GetCurrentUser() == null)
            {
                return(Unauthorized());
            }
            var tournament = (await TournamentInfo.GetAllTournamentsAsync()).FirstOrDefault(t => t.Id == tournamentId || t.Slug == tournamentId || t.ToornamentId == tournamentId);

            if (tournament.Teams.Any(i => i.Id == addTeam.Item.Id))
            {
                return(Ok());
            }
            Toornament.Participant team = new Toornament.Participant {
                Identifier = addTeam.Item.Id, Name = addTeam.Item.Name
            };

            if (!string.IsNullOrEmpty(tournament?.ToornamentId))
            {
                try
                {
                    team = await Toornament.Organizer.AddParticipantAsync(tournament.ToornamentId, team);
                }
                catch
                {
                    var parts = await Toornament.Organizer.GetParticipantsAsync(tournament.ToornamentId);

                    team = parts.FirstOrDefault(p => p.Identifier == addTeam.Item.Id);
                }
            }
            var participant = new Participant <Team> {
                Item = addTeam.Item, Information = addTeam.Information, ToornamentId = team?.Id
            };

            return(Ok(await TournamentInfo.AddTeamToTournamentAsync(tournamentId, participant)));
        }
コード例 #2
0
 public async Task <IActionResult> GetTournamentsAsync()
 {
     if (await Session.GetCurrentUser() == null)
     {
         return(Unauthorized());
     }
     return(Ok(await TournamentInfo.GetAllTournamentsAsync()));
     // return Ok(await Toornament.Organizer.GetTournamentsAsync());
 }
コード例 #3
0
        public async Task <IActionResult> GetTournamentsAsync(string tournamentId)
        {
            if (await Session.GetCurrentUser() == null)
            {
                return(Unauthorized());
            }
            var tournaments = await TournamentInfo.GetAllTournamentsAsync();

            var tournament = tournaments.FirstOrDefault(t => t.Id == tournamentId || t.Slug == tournamentId || t.ToornamentId == tournamentId);

            return(Ok(tournament));
        }
コード例 #4
0
        public async Task <IActionResult> AddPlayerToTournamentAsync(string tournamentId, Participant <Player> addPlayer)
        {
            var user = await Session.GetCurrentUser();

            if (user == null)
            {
                return(Unauthorized());
            }
            var tournament = (await TournamentInfo.GetAllTournamentsAsync()).FirstOrDefault(t => t.Id == tournamentId || t.Slug == tournamentId || t.ToornamentId == tournamentId);

            Toornament.Participant player = new Toornament.Participant {
                Identifier = addPlayer.Item.Id, Name = addPlayer.Item.Name
            };
            if (!string.IsNullOrEmpty(tournament?.ToornamentId))
            {
                player = await Toornament.Organizer.AddParticipantAsync(tournament.ToornamentId, player);
            }
            var participant = new Participant <Player> {
                Item = addPlayer.Item, Information = addPlayer.Information, ToornamentId = player.Id
            };

            return(Ok(await TournamentInfo.AddPlayerToTournamentAsync(tournamentId, participant)));
        }