public async Task <Voter?> Get(Guid voterId)
        {
            var sqlQuery = new StringBuilder()
                           .AppendLine("SELECT * FROM @Schema.voter WHERE id = @Id;")
                           .AppendLine("SELECT * FROM @Schema.vote WHERE voter_id = @Id;")
                           .ToString()
                           .InjectSchema(Schema);

            var multiQuery = await _connection.QueryMultipleAsync(
                sql : sqlQuery,
                param : new { Id = voterId },
                transaction : _transactionProvider.Get());

            return(await ReadVoterFromMultiQuery(multiQuery));
        }
        public async Task <IReadOnlyList <Vote> > GetByVoter(Guid voterId)
        {
            var voteEntities = await _connection.QueryAsync <VoteEntity>(
                sql : "SELECT * FROM @Schema.vote WHERE voter_id = @VoterId"
                .InjectSchema(Schema),
                param : new { VoterId = voterId },
                transaction : _transactionProvider.Get());

            return(voteEntities
                   .Select(e => new Vote(
                               id: e.Id,
                               voterId: e.VoterId,
                               questionId: e.QuestionId))
                   .ToArray());
        }
        public async Task <Answer?> Get(Guid answerId)
        {
            var answerEntity = await _connection.QuerySingleOrDefaultAsync <AnswerEntity>(
                sql : "SELECT * FROM @Schema.answer WHERE id = @Id"
                .InjectSchema(Schema),
                param : new { Id = answerId },
                transaction : _transactionProvider.Get());

            return(answerEntity is null
                ? default
                : new Answer(
                       id: answerEntity.Id,
                       questionId: answerEntity.QuestionId,
                       answerOrder: answerEntity.AnswerOrder,
                       text: answerEntity.Text,
                       votes: answerEntity.Votes));
        }
        protected override async Task InitializeIfNeed()
        {
            var existingTables = await GetExistingTables();

            var sqlSource      = new EmbeddedResourcesSqlSource();
            var expectedTables = sqlSource.GetAvailableTableNames().ToArray();

            foreach (var expectedTable in expectedTables)
            {
                if (!existingTables.Contains(expectedTable))
                {
                    var query = await sqlSource.ReadSqlForTable(expectedTable);

                    _ = await _connection.ExecuteAsync(
                        sql : query.InjectSchema(Schema),
                        param : _transactionProvider.Get());
                }
            }
        }
Esempio n. 5
0
        public async Task <Question?> Get(Guid questionId)
        {
            var sqlQuery = new StringBuilder()
                           .AppendLine("SELECT * FROM @Schema.question WHERE id = @Id;")
                           .AppendLine("SELECT * FROM @Schema.answer WHERE question_id = @Id ORDER BY answer_order ASC;")
                           .ToString()
                           .InjectSchema(Schema);

            var multiQuery = await _connection.QueryMultipleAsync(
                sql : sqlQuery,
                param : new { Id = questionId },
                transaction : _transactionProvider.Get());

            using (multiQuery)
            {
                var questionEntity = await multiQuery.ReadSingleOrDefaultAsync <QuestionEntity>();

                if (questionEntity is null)
                {
                    return(default);