diff options
author | crupest <crupest@outlook.com> | 2022-12-06 18:32:21 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-12-20 20:32:52 +0800 |
commit | 930269ad13bfd935a8d1c9a3cb90d92900dc1f94 (patch) | |
tree | 84ba25cc92cf75e3ac150209c65ad043774144df /docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs | |
parent | a389635f5b6e1c6033e3dec80816370d396c39c8 (diff) | |
download | crupest-930269ad13bfd935a8d1c9a3cb90d92900dc1f94.tar.gz crupest-930269ad13bfd935a8d1c9a3cb90d92900dc1f94.tar.bz2 crupest-930269ad13bfd935a8d1c9a3cb90d92900dc1f94.zip |
Develop secret api. v14
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs')
-rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs index bbd5e9a..7da6ac7 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs @@ -8,13 +8,13 @@ public class CrudService<TEntity> { protected readonly TableInfo _table; protected readonly IOptionsSnapshot<CrupestApiConfig> _crupestApiOptions; - protected readonly ILogger<CrudService<TEntity>> _logger; + private readonly ILogger<CrudService<TEntity>> _logger; - public CrudService(IOptionsSnapshot<CrupestApiConfig> crupestApiOptions, ILogger<CrudService<TEntity>> logger) + public CrudService(ServiceProvider services) { _table = new TableInfo(typeof(TEntity)); - _crupestApiOptions = crupestApiOptions; - _logger = logger; + _crupestApiOptions = services.GetRequiredService<IOptionsSnapshot<CrupestApiConfig>>(); + _logger = services.GetRequiredService<ILogger<CrudService<TEntity>>>(); } public virtual string GetDbConnectionString() @@ -78,4 +78,12 @@ public class CrudService<TEntity> var sql = _table.GenerateUpdateSql(where, update, out parameters); return await connection.ExecuteAsync(sql, parameters); } + + public virtual async Task<int> DeleteAsync(WhereClause? where) + { + var connection = await EnsureDatabase(); + DynamicParameters parameters; + var sql = _table.GenerateDeleteSql(where, out parameters); + return await connection.ExecuteAsync(sql, parameters); + } } |