Example #1
0
 /// <summary>
 /// Get info about all API tokens.
 /// </summary>
 /// <returns>
 /// A collection of API token objects.
 /// </returns>
 public async IAsyncEnumerable <ApiToken> GetAll()
 {
     using (var command = connectionProvider.CreateCommand("SELECT (id, name) FROM ApiToken WHERE deleted IS NULL"))
     {
         using (var reader = await command.ExecuteReaderAsync())
         {
             yield return(new ApiToken
             {
                 Id = reader.GetString(0),
                 Name = reader.GetString(1),
             });
         }
     }
 }
Example #2
0
        public async Task <string> Create(CreateQuizRequest request)
        {
            using (var command = connectionProvider.CreateCommand(@"
                INSERT INTO Quiz (
                    id,
                    tournamentId,
                    type,
                    room,
                    passcode
                )
                VALUES (
                    @id,
                    @tournamentId,
                    @type,
                    @room,
                    @passcode
                )
            "))
            {
                string id = Guid.NewGuid().ToString();

                command.AddParameter("@id", id);
                command.AddParameter("@tournamentId", request.TournamentId);
                command.AddParameter("@type", request.Type);
                command.AddParameter("@room", request.Room);
                command.AddParameter("@passcode", GeneratePasscode());

                await command.ExecuteNonQueryAsync();

                return(id);
            }
        }
Example #3
0
        public async Task <string> CreateTeam(string tournamentId, CreateTeamRequest request)
        {
            using var transaction = await connectionProvider.Connection.BeginTransactionAsync();

            string id = Guid.NewGuid().ToString();

            using (var command = connectionProvider.CreateCommand(@"
                INSERT INTO Team (
                    id,
                    tournamentId,
                    name
                )
                VALUES (
                    @id,
                    @tournamentId,
                    @name
                )
            "))
            {
                command.Transaction = transaction;
                command.AddParameter("@id", id);
                command.AddParameter("@tournamentId", tournamentId);
                command.AddParameter("@name", request.Name);

                await command.ExecuteNonQueryAsync();
            }

            if (request.Quizzers != null)
            {
                foreach (string personId in request.Quizzers)
                {
                    await AddPersonToTeam(id, personId, transaction);
                }
            }

            await transaction.CommitAsync();

            return(id);
        }
Example #4
0
        public async Task <string> CreateTournament(CreateTournamentRequest request)
        {
            using (var command = connectionProvider.CreateCommand(@"
                INSERT INTO Tournament (
                    id,
                    season,
                    title,
                    description,
                    location,
                    startDate,
                    endDate
                )
                VALUES (
                    @id,
                    @season,
                    @title,
                    @description,
                    @location,
                    @startDate,
                    @endDate
                )
            "))
            {
                string id = Guid.NewGuid().ToString();

                command.AddParameter("@id", id);
                command.AddParameter("@season", request.SeasonId);
                command.AddParameter("@title", request.Title);
                command.AddParameter("@description", request.Description);
                command.AddParameter("@location", request.Location);
                command.AddParameter("@startDate", request.StartDate);
                command.AddParameter("@endDate", request.EndDate);

                await command.ExecuteNonQueryAsync();

                return(id);
            }
        }
Example #5
0
        public async Task <string> CreateRound(
            string tournamentId,
            RoundType type,
            bool freeform = false
            )
        {
            using (var command = connectionProvider.CreateCommand(@"
                INSERT INTO Round (id, tournamentId, type, freeform)
                VALUES (@id, @tournamentId, @type, @freeform)
            "))
            {
                string id = Guid.NewGuid().ToString();

                command.AddParameter("@id", id);
                command.AddParameter("@tournamentId", tournamentId);
                command.AddParameter("@type", type.ToString().ToLower());
                command.AddParameter("@freeform", freeform);

                await command.ExecuteNonQueryAsync();

                return(id);
            }
        }