public async Task Post([FromBody]string value)
        {
            using (var transaction = ApplicationContext.Connection.BeginTransaction())
            {
                var command = new SqliteCommand("INSERT INTO word (text) values (@text)", ApplicationContext.Connection, transaction);
                command.Parameters.AddWithValue("@text", value);

                await command.ExecuteNonQueryAsync();

                transaction.Commit();
            }
        }
Exemplo n.º 2
0
        public async Task Add(string markdown, string context, string mode, string contents)
        {
            if (markdown == null) throw new ArgumentNullException(nameof(markdown));
            if (context == null) throw new ArgumentNullException(nameof(context));
            if (mode == null) throw new ArgumentNullException(nameof(mode));

            await Initialize();

            var key = ComputeHash(markdown, context, mode);

            using (var conn = await GetOpenConnectionAsync())
            {
                // After https://github.com/aspnet/Microsoft.Data.Sqlite/pull/172 is published to the
                // Microsoft.Data.SQLite package we can update the package and use this code instead:
                // await conn.ExecuteAsync(
                //     $"insert or replace into {CacheTableName} (Key, Contents) values (@Key, @Contents)",
                //     new { Key = key, Contents = contents });

                // Using a cast since this code should be removable in the future:
                var cmd = new SqliteCommand($"insert or replace into {CacheTableName} (Key, Contents) values (@Key, @Contents)", (SqliteConnection)conn);
                cmd.Parameters.AddWithValue("@Key", key);
                cmd.Parameters.AddWithValue("@Contents", contents);

                await cmd.ExecuteNonQueryAsync();
            }
        }
        public async Task Delete(int id)
        {
            using (var transaction = ApplicationContext.Connection.BeginTransaction())
            {
                var command = new SqliteCommand("DELETE FROM word where id = @id", ApplicationContext.Connection, transaction);
                command.Parameters.AddWithValue("@id", id);

                await command.ExecuteNonQueryAsync();

                transaction.Commit();
            }
        }
        public async Task Put(int id, [FromBody]string value)
        {
            using (var transaction = ApplicationContext.Connection.BeginTransaction())
            {
                var command = new SqliteCommand("UPDATE word set text= @text where id = @id", ApplicationContext.Connection, transaction);
                command.Parameters.AddWithValue("@id", id);
                command.Parameters.AddWithValue("@text", value);

                await command.ExecuteNonQueryAsync();

                transaction.Commit();
            }
        }